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]
posted on 2017-09-19 20:05  Beserious  阅读(126)  评论(0编辑  收藏  举报