I have a Numpy 2D array (4000,8000) from a tensor.max() operation, that stores the indices of the first dimension of a 4D array (30,4000,8000,3). I need to obtain a (4000,8000,3) array that uses the indices over this set of images and extract the pixels of each position in the 2D max array.
A = np.random.randint( 0, 29, (4000,8000), dtype=int)
B = np.random.randint(0,255,(30,4000,8000,3),dtype=np.uint8)
final = np.zeros((B.shape[1],B.shape[2],3))
r = 0
c = 0
for row in A:
c = 0
for col in row:
x = A[r,c]
final[r,c] = B[x,r,c]
c=c+1
r=r+1
print(final.shape)
Is there any vectorised way to do that? I am fighting with the RAM usage using loops. Thanks