Solved by ptrblck in post #2 
              
              
                If the tensors are not large or if you have enough memory, you could probably use this broadcasting approach: 
a = torch.arange(10)
b = torch.arange(2, 7)[torch.randperm(5)]
print((a.unsqueeze(1) == b).nonzero())
> tensor([[2, 1],
        [3, 3],
        [4, 4],
        [5, 0],
        [6, 2]])

Alt…