Selecting pixel values with a given list of 2xN tensor indices?

I’m trying to extrapolate the pixel value in a WxH img tensor with a given 2xN indices. When I tried to do the old fashioned way, by splitting apart the 2xN indices as a list of x and y values and use img[idx_x,idx_y] to extract the pixel values, I get an error saying that only datatypes of long, byte, or bool are allowed (which I can’t switch to since the locations themselves will be part of backpropagation). Is there any other way to extract pixel value from a 2D matrix with a given coordinate array beside this? Thanks!

PS:(Actually, it’s a multichannel 2D array (so actually the tensor is WxHxC) with calculated 2D indices)

Have you tried typecasting the indices: img[idx_x.long(), idx_y.long()]?

Oh cool that works! And that doesn’t seem to prevent the autograd function from going through as well! Thanks!