pytorch特殊索引切片
pytorch中None索引的效果是添加一个维度
a = torch.randn([3, 224, 224])
b = a[:, None, :, :]
print(a.shape)
print(b.shape)
运行结果:
torch.Size([3, 224, 224])
torch.Size([3, 1, 224, 224])
另外 …索引是代表往后全部的意思
a = torch.randn([3, 224, 224])
b = a[0, ...]
c = a[0, :, :]
print(a.s
原创
2021-03-29 11:03:47 ·
255 阅读 ·
2 评论