【发布时间】:2021-01-25 18:17:21
【问题描述】:
我有两个张量,张量 a 和张量 b。
我想获取张量 b 中值的所有索引。
例如。
a = torch.Tensor([1,2,2,3,4,4,4,5])
b = torch.Tensor([1,2,4])
我想要张量 a 中 1, 2, 4 的索引。我可以通过以下代码做到这一点。
a = torch.Tensor([1,2,2,3,4,4,4,5])
b = torch.Tensor([1,2,4])
mask = torch.zeros(a.shape).type(torch.bool)
print(mask)
for e in b:
mask = mask + (a == e)
print(mask)
没有for怎么办?
【问题讨论】:
标签: python numpy tensorflow pytorch