keepdims主要用于保持矩阵的二维特性
import numpy as np
a = np.array([[1,2],[3,4]]) # 按行相加,并且保持其二维特性
print(np.sum(a, axis=1, keepdims=True)) # 按行相加,不保持其二维特性
print(np.sum(a, axis=1))
输出
array([[3], [7]])
array([3, 7])
--------------------------------------------------------------
转载自:http://blog.csdn.net/u012560212/article/details/78393836