I have an MxN
array called A
which stores the data I want. I have another M x N2
array B
which stores array indices, and N2<N
. Each row of B
stores the indices of the elements I want to get from A for that row. For example, the following code works for me:
A_reduced = np.zeros((M,N2))
for i in range(M):
A_reduced[i,:] = A[i,B[i,:]]
Are there any 'vectorized' ways to extract the desired elements from A
based on B
instead of looping through each row?