Return the sum of array elements over a given axis.
Parameters: | a : array_like
axis : integer, optional
dtype : dtype, optional
out : ndarray, optional
|
---|---|
Returns: | sum_along_axis : ndarray
|
See also
Notes
Arithmetic is modular when using integer types, and no error is raised on overflow.
Examples
>>> np.sum([0.5, 1.5])
2.0
>>> np.sum([0.5, 1.5], dtype=np.int32)
1
>>> np.sum([[0, 1], [0, 5]])
6
>>> np.sum([[0, 1], [0, 5]], axis=1)
array([1, 5])
If the accumulator is too small, overflow occurs:
>>> np.ones(128, dtype=np.int8).sum(dtype=np.int8)
-128