Can this two stage indexing operation be merged into one?

I have the following codes:

H = image.shape[1]
W = image.shape[2]
  
# a is some const integer
x = torch.arange(0, H)
y = torch.arange(0, W)
image_scale = image[:, x * a % H, :][:, :, y * a % W]

I’m wondering whether or not the code of the last line could be merged into the single one. Also, is there a more effective method to implement this logic?

What do you mean by “the single one”? What does that refer to?

only index the image once. like image[:, :, :], it is a indexing operation.

You probably want to use image[:, x * a % H, y * a % W].