- sum(x: array, /, *, axis: Optional[Union[int, Tuple[int, ...]]] = None, dtype: Optional[dtype] = None, keepdims: bool = False) array ¶
Calculates the sum of the input array
Nequal the number of elements over which to compute the sum.
0, the sum is
0(i.e., the empty sum).
For floating-point operands,
NaN, the sum is
x (array) – input array. Should have a numeric data type.
axis (Optional[Union[int, Tuple[int, ...]]]) – axis or axes along which sums must be computed. By default, the sum must be computed over the entire array. If a tuple of integers, sums must be computed over multiple axes. Default:
dtype (Optional[dtype]) –
data type of the returned array. If
if the default data type corresponding to the data type “kind” (integer or floating-point) of
xhas a smaller range of values than the data type of
xhas data type
int64and the default data type is
xhas data type
uint64and the default data type is
int64), the returned array must have the same data type as
xhas a floating-point data type, the returned array must have the default floating-point data type.
xhas a signed integer data type (e.g.,
int16), the returned array must have the default integer data type.
xhas an unsigned integer data type (e.g.,
uint16), the returned array must have an unsigned integer data type having the same number of bits as the default integer data type (e.g., if the default integer data type is
int32, the returned array must have a
If the data type (either specified or resolved) differs from the data type of
x, the input array should be cast to the specified data type before computing the sum. Default:
keyword argument is intended to help prevent data type overflows.
keepdims (bool) – if
True, the reduced axes (dimensions) must be included in the result as singleton dimensions, and, accordingly, the result must be compatible with the input array (see Broadcasting). Otherwise, if
False, the reduced axes (dimensions) must not be included in the result. Default:
out (array) – if the sum was computed over the entire array, a zero-dimensional array containing the sum; otherwise, an array containing the sums. The returned array must have a data type as described by the