Sum of array elements over a given axis.html
Parameters: | a : array_likepython
axis : None or int or tuple of ints, optionalgithub
dtype : dtype, optionalui
out : ndarray, optionalspa
keepdims : bool, 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, 0.7, 0.2, 1.5], dtype=np.int32) 1 >>> np.sum([[0, 1], [0, 5]]) 6 >>> np.sum([[0, 1], [0, 5]], axis=0) #axis=0是按列求和 array([0, 6]) >>> np.sum([[0, 1], [0, 5]], axis=1) #axis=1 是按行求和 array([1, 5])
If the accumulator is too small, overflow occurs:
>>> np.ones(128, dtype=np.int8).sum(dtype=np.int8) -128