Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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:

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. If there is a pytorch/linear away to tackle the mapping that’d be great.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

>>> 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])
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading