numpy 整数索引 解释

import numpy as np
x= np.array([[1,2],[3,4],[5,6]])

y=x[[0,1,2],[0,1,0]]
0,0 
1,1
2,0
print(y)
import numpy as np
x = np.array([[0,1,2],[3,4,5],[6,7,8],[9,10,11]])
rows = np.array([[0,0],[3,3]])
print(rows)
cols = np.array([[0,2],[0,2]])
print(cols)
y = x[rows,cols]
# 0,0
# 0,2
# 3,0
# 3,2
print(y)

猜你喜欢

转载自blog.csdn.net/qq_35899407/article/details/89399215