简体   繁体   English

Map张量值到另一个张量

[英]Map tensor values to another tensor

Hi everyone I have two tensors, one tensor has as values the indicies to another tensor which contain the values I want mapped for example:大家好,我有两个张量,一个张量的值是另一个张量的索引,其中包含我想要映射的值,例如:

a = tensor([0, 2, 5, 1, 0, 0, 4, 3, 0, 0, 0, 2,2,1])
b = tensor([1.5, 2.7, 1.8, 7.0, 3.9, 10.0])

I would like to produce a new tensor in which the values of b replace the index values in a as such:我想生成一个新的张量,其中 b 的值替换 a 中的索引值,如下所示:

new_tensor = tensor([1.5, 1.8, 10.0, 2.7, 1.5, 1.5, ... ])

Id like to do it without performing some time of for loop.我喜欢在不执行 for 循环的情况下这样做。 If there is a pytorch/linear away to tackle the mapping that'd be great.如果有一个 pytorch/linear 来处理映射那就太好了。

>>> b[a]
tensor([ 1.5000,  1.8000, 10.0000,  2.7000,  1.5000,  1.5000,  3.9000,  7.0000,
         1.5000,  1.5000,  1.5000,  1.8000,  1.8000,  2.7000])

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

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