import numpy as np
data = np.arange(10000).reshape(100, 100)
print(data)
index = np.array([[10, 20],
[30, 40],
[50, 60]])
print(index.shape)
print(index.T[0])
selected = data[index.T[0], index.T[1]]
print(selected)
打印结果为:
[[ 0 1 2 ... 97 98 99]
[ 100 101 102 ... 197 198 199]
[ 200 201 202 ... 297 298 299]
...
[9700 9701 9702 ... 9797 9798 9799]
[9800 9801 9802 ... 9897 9898 9899]
[9900 9901 9902 ... 9997 9998 9999]]
(3, 2)
[10 30 50]
[1020 3040 5060]