二维数组
axis=0
:表示从上往下
axis=1
:表示从左往右
temp = np.array([[1, 2], [3, 4]])
print("原矩阵数组:\n",temp)
axis0 = temp.sum(0) #从上到下求和
axis1 = temp.sum(1) #从左往右求和
print("axis0(从上到下求和):", axis0)
print("axis0(从左往右求和):", axis1)
三维数组
temp = np.array([[[1, 2],[3, 4]], [[5, 6], [7, 8]]])
print("原矩阵数组:\n",temp)
axis0 = temp.sum(0) #沿着通道层数方向求和
axis1 = temp.sum(1) #从上到下求和
axis2 = temp.sum(2) #从左往右求和
print("axis0:\n", axis0)
print("axis1:\n", axis1)
print("axis2:\n", axis2)
标签:axis0,axis1,temp,求和,sum,和谈,print,axis
From: https://www.cnblogs.com/fengxijlu/p/17471818.html