sum is a built-in function, and its function is to sum, but the summation method of different parameters is different.
L=range(5) I am (L)
Generate a list 0-4 whose sum is 10. The result obtained is also 10.
But we can see something like sum(L, axis = 1 or 0). What's the meaning? For one-dimensional arrays, this parameter has no meaning, he can only use axis = 0 . But for a two-dimensional array , axis = 0 means column-wise addition, and axis = 1 means row-wise addition.
import numpy as np a=np.array([[0,1,2],[2,3,4]]) a.sum(axis=1) a.sum(axis=0)
The output is array([3, 9]) and array([2, 4, 6]) respectively. At a glance!