nlcpy.cumsum

nlcpy.cumsum(a, axis=None, dtype=None, out=None)

Returns the cumulative sum of the elements along a given axis.

Parameters
aarray_like

Input array.

axisint, optional

Axis along which the cumulative sum is computed. The default (None) is to compute the cumsum over the flattened array.

dtypedtype, optional

Type of the returned array and of the accumulator in which the elements are summed. If dtype is not specified, it defaults to the dtype of a, unless dtype is nlcpy.int32. unless dtype is nlcpy.int32.

outndarray, optional

Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type will be cast if necessary.

Returns
cumsum_along_axisndarray

A new array holding the result is returned unless out is specified, in which case a reference to out is returned. The result has the same size as a, and the same shape as a if axis is not None or a is a 1-d array.

See also

sum

Sum of array elements over a given axis.

diff

Calculates the n-th discrete difference along the given axis.

Note

Arithmetic is modular when using integer types, and no error is raised on overflow.

Examples

>>> import nlcpy as vp
>>> a = vp.array([[1,2,3], [4,5,6]])
>>> a
array([[1, 2, 3],
       [4, 5, 6]])
>>> vp.cumsum(a)
array([ 1,  3,  6, 10, 15, 21])
>>> vp.cumsum(a, dtype=float)
array([ 1.,  3.,  6., 10., 15., 21.])
>>> vp.cumsum(a, axis=0)
array([[1, 2, 3],
       [5, 7, 9]])
>>> vp.cumsum(a, axis=1)
array([[ 1,  3,  6],
       [ 4,  9, 15]])