I have a source multidimensional array of shape (a,b,c,c,d) which stores vectors/data of size d, and another array of shape (a,b,e,2) that stores e indices of size 2. 2-dimensional values correspond to the indices 2-3 of the data array (both dimensions of size c). Note that both arrays share the same a,b dimension sizes.
What I want to do is to use these indices to retrieve rows of size d from the first array. So that, the output array should have size (a,b,e,d), i.e. e vectors of size d along the a,b dimensions.
a, b, c, d = 3,5,7,9
e = 11
data = np.random.rand(a,b,c,c,d)
inds = np.random.randint(0,c, size=(a,b,e,2))
res = data[:, :, inds[:,:,:,0], inds[:,:,:,1],:]
print(' - Obtained shape:', res.shape)
print(' - Desired shape:', (a,b,e,d))
# - Obtained shape: (3, 5, 3, 5, 11, 9)
# - Desired shape: (3, 5, 11, 9)