cfdm.Data.sum

Data.sum(axes=None)[source]

Return the sum of an array or the sum along axes.

Missing data array elements are omitted from the calculation.

See also

max, min

Parameters
axes: (sequence of) int, optional

The axes over which to calculate the sum. By default the sum over all axes is returned.

Each axis is identified by its integer position in the data. Negative integers counting from the last position are allowed.

Parameter example:

axes=0

Parameter example:

axes=-1

Parameter example:

axes=[1, -2]

Returns
Data

The sum of the data along the specified axes.

Examples

>>> d = cfdm.Data(numpy.arange(24).reshape(1, 2, 3, 4))
>>> d
<Data(1, 2, 3, 4): [[[[0, ..., 23]]]]>
>>> print(d.array)
[[[[ 0  1  2  3]
   [ 4  5  6  7]
   [ 8  9 10 11]]
  [[12 13 14 15]
   [16 17 18 19]
   [20 21 22 23]]]]
>>> e = d.sum()
>>> e
<Data(1, 1, 1, 1): [[[[276]]]]>
>>> print(e.array)
[[[[276]]]]
>>> e = d.sum(2)
>>> e
<Data(1, 2, 1, 4): [[[[12, ..., 57]]]]>
>>> print(e.array)
[[[[12 15 18 21]]
  [[48 51 54 57]]]]
>>> e = d.sum([-2, -1])
>>> e
<Data(1, 2, 1, 1): [[[[66, 210]]]]>
>>> print(e.array)
[[[[ 66]]
  [[210]]]]