Indexing 3d numpy array with 2d array
问题 I would like to create a numpy 2d-array based on values in a numpy 3d-array, using another numpy 2d-array to determine which element to use in axis 3. import numpy as np #-------------------------------------------------------------------- arr_3d = np.arange(2*3*4).reshape(2,3,4) print('arr_3d shape=', arr_3d.shape, '\n', arr_3d) arr_2d = np.array(([3,2,0], [2,3,2])) print('\n', 'arr_2d shape=', arr_2d.shape, '\n', arr_2d) res_2d = arr_3d[:, :, 2] print('\n','res_2d example using element 2 of