I would like to write a function that achieves the behavior described in this question.
That is, I want to zero out duplicate values in each row of a matrix in PyTorch. For example, given a matrix
torch.Tensor(([1, 2, 3, 4, 3, 3, 4],
[1, 6, 3, 5, 3, 5, 4]])
I would like to get
torch.Tensor(([1, 2, 3, 4, 0, 0, 0],
[1, 6, 3, 5, 0, 0, 4]])
or
torch.Tensor(([1, 2, 3, 4, 0, 0, 0],
[1, 6, 3, 5, 4, 0, 0]])
According to the linked question, torch.unique() alone is not sufficient. I want to know how to implement this function without a loop.