Solved by ptrblck in post #3 
              
              
                F.one_hot should yield the same result as the scatter operation  : 
x = torch.tensor([1, 2, 0, 2, 2, 2, 2, 1])
F.one_hot(x, num_classes=4)