【发布时间】:2021-04-10 11:51:05
【问题描述】:
我无法理解索引的复杂性——张量的非连续索引是如何工作的。这是一个示例代码及其输出
import torch
def describe(x):
print("Type: {}".format(x.type()))
print("Shape/size: {}".format(x.shape))
print("Values: \n{}".format(x))
indices = torch.LongTensor([0,2])
x = torch.arange(6).view(2,3)
describe(torch.index_select(x, dim=1, index=indices))
返回输出为
类型:torch.LongTensor 形状/大小:torch.Size([2, 2]) 值: 张量([[0, 2], [3, 5]])
有人能解释一下它是如何到达这个输出张量的吗? 谢谢!
【问题讨论】:
标签: python indexing pytorch tensor