Hi, I have a 4x4
tensor, for example [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]]
and I also have a mapping dict, like {4: 5, 7: 10, 13: 10, 15: 1, 16: 1}
. Is there any way to map the value in the tensor using this dictionary efficiently?
2 Likes
Hi, did you manage to find a way to do this?
Thank you
I do not know how efficient it is but it is readable by using the apply function. If you have the tensor t
and the dictionary d
, then simply write t.apply_(d.get)
.