Create a sample 3D array with shape (10, 33, 66)
data_3d = np.random.random((10, 33, 66))
Create a 2D index array with shape (33, 66) representing indices for the first dimension
index_2d = np.random.randint(0, 10, size=(33, 66))
How to slice a 2D array with shape (33,66) from the 3D array based on the index array?
index_2d? For example, ifindex_2d[1,5] = 3, which index do you want fromdata_3d? Is itdata_3d[3, 1, 5]?take_along_axis,res=np.take_along_axis(data_3d, index_2d[None], axis=0)res1=data_3d[index_2d, np.arange(33)[:,None], np.arange(66)]