cf.Data.cumsum

Data.cumsum(axis, masked_as_zero=False)[source]

Return the data cumulatively summed along the given axis.

New in version 3.0.0.

See also

sum

Parameters
axis: int, optional

Select the axis over which the cumulative sums are to be calculated.

masked_as_zero: bool, optional

If True then set missing data values to zero before calculating the cumulative sum. By default the output data will be masked at the same locations as the original data.

Returns
Data

The data with the cumulatively summed dimension.

Examples:

>>> d = cf.Data(numpy.arange(12).reshape(3, 4))
>>> print(d.array)
[[ 0  1  2  3]
 [ 4  5  6  7]
 [ 8  9 10 11]]
>>> print(d.cumsum(0).array)
[[ 0  1  2  3]
 [ 4  6  8 10]
 [12 15 18 21]]
>>> print(d.cumsum(1).array)
[[ 0  1  3  6]
 [ 4  9 15 22]
 [ 8 17 27 38]]
>>> d[1, 1] = cf.masked
>>> print(d.array)
[[0 1 2 3]
 [4 -- 6 7]
 [8 9 10 11]]
>>> print(d.cumsum(1).array)
[[0 1 3 6]
 [4 -- 10 17]
 [8 17 27 38]]
>>> print(d.cumsum(1, masked_as_zero=True).array)
[[ 0  1  3  6]
 [ 4  4 10 17]
 [ 8 17 27 38]]