[英]What is the difference between ... and : in Pytorch tensors and numpy indexing
I am trying to get used to Pytorch indexing.我正在尝试习惯 Pytorch 索引。 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)
但是我无法理解 tensor[:,-1] (应该打印最后一列)和 tensor[...,-1] 之间的区别,它打印不同的 output (输出2)
import torch
tensor = torch.rand([3,3,3,3])
print('Output1')
print(tensor[:,-1])
print('Output2')
print(tensor[...,-1])
It looks like the following indices are equivalent看起来以下索引是等效的
tensor[:, -1] == tensor[:, -1, :, :]
tensor[..., -1] == tensor[:, :, :, -1]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.