summation numpy code example
Example 1: sum along axis python
import numpy as np
matrix=np.ones((10,10))
print(matrix.sum(axis=0))
print(matrix.sum(axis=1))
Example 2: sum of a numpy array
>>> 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)
array([0, 6])
>>> np.sum([[0, 1], [0, 5]], axis=1)
array([1, 5])
>>> np.sum([[0, 1], [np.nan, 5]], where=[False, True], axis=1)
array([1., 5.])
Example 3: python np.sum
npsum = np.sum(array)