尝试对具有第二维索引列表(a
)的numpy数组(index_dim2
)进行切片。期望值应为b
。特别是something_with_index_dim2
是什么?
import numpy as np
a=np.arange(24).reshape(4,3,2)
print(a)
array([[[ 0, 1],
[ 2, 3],
[ 4, 5]],
[[ 6, 7],
[ 8, 9],
[10, 11]],
[[12, 13],
[14, 15],
[16, 17]],
[[18, 19],
[20, 21],
[22, 23]]])
a.shape
(4, 3, 2)
index_dim2=np.array([0,1,2,2])
b=a[something_with_index_dim2]
print(b) #desired output
array([[[ 0, 1]],
[[ 8, 9]],
[[16, 17]],
[[22, 23]]])