rollingAggregate<T> method

Future<List<T>> rollingAggregate<T>({
  1. required int axis,
  2. required int windowSize,
  3. required T aggregator(
    1. NDArray window
    ),
  4. int step = 1,
})

Applies a rolling aggregation along an axis.

Example:

var arr = NDArray([1, 2, 3, 4, 5]);

var rollingMean = await arr.rollingAggregate(
  axis: 0,
  windowSize: 3,
  aggregator: (window) => window.mean(),
);
print(rollingMean); // [2.0, 3.0, 4.0]

Implementation

Future<List<T>> rollingAggregate<T>({
  required int axis,
  required int windowSize,
  required T Function(NDArray window) aggregator,
  int step = 1,
}) async {
  final results = <T>[];

  await for (var window in slidingWindow(
    axis: axis,
    windowSize: windowSize,
    step: step,
  )) {
    results.add(aggregator(window));
  }

  return results;
}