nreduce - windowed reduction along an axis
res =
arr.nreduce(n,
op[, axis])
Performs a "windowed" or "n-way" reduction on
arr along the specified axis using the operator or
procedure op. This is similar to APL n op
/ arr and n op.
n is the window size. If n is positive, the window
is forward-looking. If n is negative, the window size is
abs(n) and the direction of reduction is flipped.
The result has the same rank as arr, but the dimension
along axis is reduced to arr.shape()[axis]
- abs(n) + 1. Each element in the result represents the
reduction of a window of n elements from the input.
If axis is omitted, it defaults to the last dimension
(-1).
Returns the windowed reduction array.
ArgCheck: Thrown if the number of arguments is not 3 or 4.
RangeCheck: Thrown if abs(n) is greater
than the size of arr along axis, or if axis is
out of bounds.
ShapeCheck: Thrown if the resulting axis
length would be less than or equal to zero.
a = [1, 2, 3, 4, 5]
a.nreduce(2, `+)
2 3 4 5
a.nreduce(3, `max)
3 4 5 // (max(1,2,3), max(2,3,4), max(3,4,5))
a = {"a", "b", "c", "d", "e", "f", "g"}
a.nreduce(3, `##)
abc bcd cde def efg
arr.nreduce(-3,`##)
cba dcb edc fed gef