cfdm.Data.sum

Data.sum(axes=None, squeeze=False, split_every=None, inplace=False)[source]

Calculate sum values.

Calculates the sum value or the sum values along axes.

See https://ncas-cms.github.io/cf-python/analysis.html#collapse-methods for mathematical definitions.

See also

max, min

Parameters:
axes: (sequence of) int, optional

The axes to be collapsed. By default all axes are collapsed, resulting in output with size 1. Each axis is identified by its positive or negative integer position. If axes is an empty sequence then the collapse is applied to each scalar element and the result has the same shape as the input data.

squeeze: bool, optional

By default, the axes which are collapsed are left in the result as dimensions with size one, so that the result will broadcast correctly against the input array. If set to True then collapsed axes are removed from the data.

split_every: int or dict, optional

Determines the depth of the dask recursive aggregation. If set to or more than the number of input Dask chunks, the aggregation will be performed in two steps, one partial collapse per input chunk and a single aggregation at the end. If set to less than that, an intermediate aggregation step will be used, so that any of the intermediate or final aggregation steps operates on no more than split_every inputs. The depth of the aggregation graph will be the logarithm to the base split_every of N, the number input chunks along reduced axes. Setting to a low value can reduce cache size and network transfers, at the cost of more CPU and a larger dask graph. See dask.array.reduction for details.

By default, dask heuristically decides on a good value. A default can also be set globally with the split_every key in dask.config.

Added in version (cfdm): 1.11.2.0

inplace: bool, optional

If True then do the operation in-place and return None.

Returns:
Data or None

The collapsed data, or None if the operation was in-place.

Examples

>>> a = np.ma.arange(12).reshape(4, 3)
>>> d = cfdm.Data(a, 'K')
>>> d[1, 1] = cfdm.masked
>>> print(d.array)
[[0 1 2]
 [3 -- 5]
 [6 7 8]
 [9 10 11]]
>>> d.sum()
<Data(1, 1): [[62]] K>
>>> w = np.linspace(1, 2, 3)
>>> print(w)
[1.  1.5 2. ]
>>> d.sum(weights=cfdm.Data(w, 'm'))
<Data(1, 1): [[97.0]] K>