Home > front end >  What is the difference between ... and : in Pytorch tensors and numpy indexing
What is the difference between ... and : in Pytorch tensors and numpy indexing

Time:07-26

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])

CodePudding user response:

It looks like the following indices are equivalent

tensor[:, -1] == tensor[:, -1, :, :]
tensor[..., -1] == tensor[:, :, :, -1]
  • Related