code: def aggregate_array(ts_values, agg_periods=7, agg_func=np.sum):
      """Aggregates input array.
      Divides array from left to right into bins of size agg_periods, and applies agg_func to each block.
      Drops records from the left if needed to ensure all bins are full.
  
      :param ts_values: list, np.array, or pd.Series to aggregate
      :param agg_periods: number of periods to combine in aggregation
      :param agg_func: aggregation function, e.g. np.max, np.sum. Must take an array and returns a number
      :return: array, aggregated so that every agg_periods periods are combined into one
  
      Examples:
      >>> aggregate_array([1.0, 2.0, 3.0, 4.0], 2, np.sum)
      array([3., 7.])
      >>> aggregate_array(pd.Series([1.0, 2.0, 3.0, 4.0, 5.0]), 2, np.sum)
      array([5., 9.])
      >>> aggregate_array(np.array([1.0, 2.0, 3.0, 4.0, 5.0]), 2, np.max)
      array([3., 5.])
      """
      ts_values = np.array(ts_values)
      n_periods = len(ts_values)
  
      drop_first_periods = (
          n_periods % agg_periods
      )  # drop these periods from the front, to ensure all bins are full
      if drop_first_periods == n_periods:
          drop_first_periods = 0
          warnings.warn(
              f"Requested agg_periods={agg_periods}, but there are only {n_periods}. Using all for aggregation"
          )
      elif drop_first_periods > 0:
          log_message(
              f"Requested agg_periods={agg_periods} for data of length {n_periods}. Dropping first"
              f" {drop_first_periods} records before aggregation",
              LoggingLevelEnum.INFO,
          )
  
      # creates dummy time index for aggregation
      dates = pd.date_range(
          "2018-01-01",
          periods=n_periods - drop_first_periods,
          freq="1D",
      )
      ts = pd.Series(ts_values[drop_first_periods:], index=dates)
      aggregated_array = (
          ts.resample(f"{agg_periods}D", closed="left")
          .agg(lambda x: agg_func(x))
          .values
      )
      return aggregated_array
  
imports: import math
  import warnings
  from collections import namedtuple
  from enum import Enum
  from functools import partial
  from typing import List
  from typing import Optional
  from typing import Union
  import numpy
  import pandas
  from scipy.stats import pearsonr
  from sklearn.metrics import mean_absolute_error
  from sklearn.metrics import mean_squared_error
  from sklearn.metrics import median_absolute_error
  from sklearn.metrics import r2_score
  from greykite.common.constants import ACTUAL_COL
  from greykite.common.constants import COVERAGE_VS_INTENDED_DIFF
  from greykite.common.constants import LOWER_BAND_COVERAGE
  from greykite.common.constants import PREDICTED_COL
  from greykite.common.constants import PREDICTED_LOWER_COL
  from greykite.common.constants import PREDICTED_UPPER_COL
  from greykite.common.constants import PREDICTION_BAND_COVERAGE
  from greykite.common.constants import PREDICTION_BAND_WIDTH
  from greykite.common.constants import UPPER_BAND_COVERAGE
  from greykite.common.logging import LoggingLevelEnum
  from greykite.common.logging import log_message
label_desc: Use image node_id 3 for calling a global function with example usage: aggregate_array(ts_values, agg_periods, agg_func) and returns: aggregated_array