08-numpy-笔记-sum
求和:
axis = 0 按列求和
axis = 1 按行求和
>>> import numpy as np >>> a = np.mat([[1,2,3],[4,5,6]]) >>> a matrix([[1, 2, 3], [4, 5, 6]]) >>> a.sum(axis = 0) matrix([[5, 7, 9]]) >>> a.sum(axis = 1) matrix([[ 6], [15]]) >>> a.sum() 21
求和:
axis = 0 按列求和
axis = 1 按行求和
>>> import numpy as np >>> a = np.mat([[1,2,3],[4,5,6]]) >>> a matrix([[1, 2, 3], [4, 5, 6]]) >>> a.sum(axis = 0) matrix([[5, 7, 9]]) >>> a.sum(axis = 1) matrix([[ 6], [15]]) >>> a.sum() 21