python numpy
python keepdims = True和 keepdims = False的区别,设置为True就是保持原来的列矩阵,否则就变成一位数组
import numpy as np
y = np.array([[1,2,3], [4,5,6], [7,8,9], [10, 11, 12]])
x = np.array([[1,0,1]])
z = np.array([[1],[2],[3]])
w = np.array(x)
print (np.sum(y, axis = 1, keepdims=True))
print (np.sum(y, axis = 1))
print (z + x)
切片和np.arange()的区别
import numpy as np
y = np.array([[1,2,3], [4,5,6], [7,8,9]])
x = np.array([0,2,1])
print(y[0:3,x])
print(y[np.arange(3),x])
结果
[[1 3 2]
[4 6 5]
[7 9 8]]
[1 6 8]
原文地址:http://www.cnblogs.com/pk28/
与有肝胆人共事,从无字句处读书。
欢迎关注公众号:
欢迎关注公众号: