The above code for determination of tensor index is very useful, lately I came across an anomaly when doing this operation.
This is function I am using for determining index of host tensor from target tensor.
def get_index(host, target):
        diff = target.unsqueeze(1) - host.unsqueeze(0)
        dsum = torch.abs(diff).sum(-1)
        loc = (dsum == 0).nonzero()
        return loc[:, -1]

for example I wanted to extract the index from 2D Tensor of shape (40,2). Such that Target[:,1] = 0 and 1 . This is the result I got:
tensor([[0.0000, 0.0000],
        [1.0000, 0.0000],
        [0.0000, 0.1111],
        [1.0000, 0.1111],
        [0.0000, 0.2222],
        [1.0000, 0.2222],
        [0.0000, 0.3333],
        [1.0000, 0.3333],
        [0.0000, 0.4444],
        [1.0000, 0.4444],
        [0.0000, 0.5556],
        [1.0000, 0.5556],
        [0.0000, 0.7778],
        [1.0000, 0.7778],
        [0.0000, 0.8889],
        [1.0000, 0.8889],
        [0.0000, 1.0000],
        [1.0000, 1.0000]])

The value of 0.6667 is missing from this output. Can anyone explain this abnormality or am I doing something wrong. @ptrblck could you please suggest anything.