cf.Data.cumsum¶
-
Data.
cumsum
(axis, masked_as_zero=False, inplace=False)[source]¶ Return the data cumulatively summed along the given axis.
New in version 3.0.0.
See also
- 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.
Note
Sums produced entirely from masked elements will always result in masked values in the output data, regardless of the setting of masked_as_zero.
- inplace:
bool
, optional If True then do the operation in-place and return
None
.
- axis:
- Returns
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(axis=0).array) [[ 0 1 2 3] [ 4 6 8 10] [12 15 18 21]] >>> print(d.cumsum(axis=1).array) [[ 0 1 3 6] [ 4 9 15 22] [ 8 17 27 38]]
>>> d[0, 0] = cf.masked >>> d[1, 1] = cf.masked >>> d[2, 0:2] = cf.masked >>> print(d.array) [[-- 1 3 6] [ 4 -- 10 17] [-- -- 10 21]] >>> print(d.cumsum(axis=1).array) [[-- 1 3 6] [ 4 -- 10 17] [-- -- 10 21]] >>> print(d.cumsum(axis=1, masked_as_zero=True).array) [[-- 1 3 6] [ 4 4 10 17] [-- -- 10 21]]