What is the difference between … and : in Pytorch tensors and numpy indexing

Question:

I am trying to get used to Pytorch indexing. However I couldn’t understand the difference between tensor[:,-1] (which should print the last column) and tensor[…,-1] which is printing different output (output2)

import torch
tensor = torch.rand([3,3,3,3])
print('Output1')
print(tensor[:,-1])
print('Output2')
print(tensor[...,-1])
Asked By: Youcef

||

Answers:

It looks like the following indices are equivalent

tensor[:, -1] == tensor[:, -1, :, :]
tensor[..., -1] == tensor[:, :, :, -1]
Answered By: MaryRa