I want to construct an array V1
, of shape (n,p,q)
using an array of indices, idx
, with the same shape, applied to an array V0
, of shape (p,q)
. The way to construct it with a loop is the following.
for i in range(n):
V1[i,:,:] = V0[idx[i,:,:],range(q)]
In other words, the idx[i,:,:]
array contains indices for the elements of the 1st dimension of V0
. I apply it with the associated index of the 2nd dimension, captured in range(q)
, to get the corresponding element along the fist dimension of the final array V1
.
My question is the following: is there a way to construct V1
without looping, by using broadcasting/indexing techniques?
Thank you.