One hot encoding in pytorch
I am really new to coding, right now I am trying to turn my label to one hot encoding. I have already done transferring the np.array to tensor as shown below


tensor([4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 1., 1., 1.,
        1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 3., 3., 3., 3., 3., 3.,
        3., 3., 3., 3., 3., 3., 3., 3., 3., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
        0., 0., 0., 0., 0., 0., 2., 2., 2., 2., 2., 2., 2., 2., 2., 2., 2., 2.,
        2., 2., 2.], dtype=torch.float64)





and I am using code to do one hot encoding 

aaa = F.one_hot(torch_qyh, num_classes=5)



However, there is an error showing &quot;RuntimeError: one_hot is only applicable to index tensor.&quot; Any help would appreciated.

You will have to convert it in long type. Can't do it with float. F.one_hot only takes LongTensor.
F.one_hot(t.long())

