ufunc.accumulate(self, array, axis=0, dtype=None, out=None)

Accumulates the result of applying the operator to all elements.

For example, nlcpy.add.accumulate() is equivalent to nlcpy.cumsum(). For a multi-dimensional array, accumulate is applied along only one axis (axis zero by default; see Examples below) so repeated use is necessary if one wants to accumulate over multiple axes.


The array to act on.

axisint, optional

The axis along which to apply the accumulation; default is zero.

dtypedtype, optional

The type used to represent the intermediate results. Defaults to the data type of the output array if such is provided, or the data type of the input array if no output array is provided.

outndarray, None, or tuple of ndarray and None, optional

A location into which the result is stored. If not provided or None, a freshly-allocated array is returned.


The accumulated array. If out was supplied, r is a reference to out.


  • If a list is passed to the parameter a of power.reduceat(), there are cases where ValueError occurs.


1-D array examples:

>>> import nlcpy as vp
>>> vp.add.accumulate([2, 3, 5])
array([ 2,  5, 10])
>>> vp.multiply.accumulate([2, 3, 5])
array([ 2,  6, 30])

2-D array examples:

>>> I = vp.eye(2)
>>> I
array([[1., 0.],
       [0., 1.]])

Accumulate along axis 0 (rows), down columns:

>>> vp.add.accumulate(I, 0)
array([[1., 0.],
       [1., 1.]])
>>> vp.add.accumulate(I) # no axis specified = axis zero
array([[1., 0.],
       [1., 1.]])

Accumulate along axis 1 (columns), through rows:

>>> vp.add.accumulate(I, 1)
array([[1., 1.],
       [0., 1.]])