ee.Array.accum

Accumulates elements of an array along the given axis, by setting each element of the result to the reduction of elements along that axis up to and including the current position. May be used to make a cumulative sum, a monotonically increasing sequence, etc.

UsageReturns
Array.accum(axis, reducer)Array
ArgumentTypeDetails
this: arrayArray

Array to accumulate.

axisInteger

Axis along which to perform the accumulation.

reducerReducer, default: null

Reducer to accumulate values. Default is SUM, to produce the cumulative sum of each vector along the given axis.

Examples

JavaScript

print(ee.Array([-1]).accum(0));  // [-1]
print(ee.Array([-2, 1]).accum(0));  // [-2, -1]
print(ee.Array([-2, 1, 9]).accum(0));  // [-2, -1, 8]

// accum over 2D arrays with different axes.
print(ee.Array([[1, 3], [5, 7]]).accum(0));  // [[1,3],[6,10]]
print(ee.Array([[1, 3], [5, 7]]).accum(1));  // [[1,4],[5,12]]

// sum is the default reducer.
print(ee.Array([2, -2, 3, 1]).accum(0));  // [2,0,3,4]
print(ee.Array([2, -2, 3, 1]).accum(0, ee.Reducer.sum()));  // [2,0,3,4]

// Some example reducers.
print(ee.Array([2, -2, 3, 1]).accum(0, ee.Reducer.max()));  // [2,2,3,3]
print(ee.Array([2, -2, 3, 1]).accum(0, ee.Reducer.mean()));  // [2,0,1,1]
print(ee.Array([2, -2, 3, 1]).accum(0, ee.Reducer.min()));  // [2,-2,-2,-2]
print(ee.Array([2, -2, 3]).accum(0, ee.Reducer.product()));  // [2,-4,-12]

Python

# Your example goes here!