Indexing a batch of images (3D numpy array) using a 2D array to get pixel values for each image
Think I solved it. Just needed to get the diagonal of the output:
output = images[:,indices[:,0],indices[:,1]
np.diag(output) gives pixel values for each image at x,y positions (indices).
I have a 3D array representing a batch of images (batch_size x W x H)
images = np.random.rand(8,100,100)
and a 2D array (batch_size x 2)
indices = np.random.randint(0, 100, size=(8, 2))
which contains x,y indices for accessing pixel values of the images. The following
images[:,indices[:,0],indices[:,1]
returns an array of shape (8,8) but I would like to get an array of shape (8,) that contains pixel values for each image at the respective x, y positions stored in indices.
Looking for a way to index the array w/o using a for loop.