axis = 0, operate on the horizontal axis (0th dimension), the direction of operation is vertical operation. Find the sum, maximum, minimum, etc.
axis = 1, process operation on the vertical axis (1st dimension), the direction of operation is horizontal operation. Find the sum, maximum, minimum, etc.
import numpy as np
import numpy as np
data = np.array([[1,1,1,1],
[2,2,2,2],
[3,3,3,3],
[4,4,4,4]])
Out[1]:
array([[1, 1, 1, 1],
[2, 2, 2, 2],
[3, 3, 3, 3],
[4, 4, 4, 4]])
#对横轴进行操作,即纵向运算
np.sum(data,axis=0)
Out[2]:
array([10, 10, 10, 10])
#对纵轴进行操作,即横向运算
np.sum(data,axis=1)
Out[3]:
array([ 4, 8, 12, 16])
references:
https://blog.csdn.net/brucewong0516/article/details/79030994