0

尝试使用第二维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]]])
4

0 回答 0