繁体   English   中英

... 和:在 Pytorch 张量和 numpy 索引中有什么区别

[英]What is the difference between ... and : in Pytorch tensors and numpy indexing

我正在尝试习惯 Pytorch 索引。 但是我无法理解 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])

看起来以下索引是等效的

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM