Skip to content
Advertisement

Pytorch tensor – How to get the indexes by a specific tensor

I have a tensor

JavaScript

and a query tensor

JavaScript

Is there a way to get the indexes of q like

JavaScript

in pytorch?

Advertisement

Answer

How about

JavaScript

Comparing t == q performs element-wise comparison between t and q, since you are looking for entire row match, you need to .sum(dim=1) along the rows and see what row is a perfect match == t.size(1).


As of v0.4.1, torch.all() supports dim argument:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement