#如何快速构造one-hot向量
from torch.nn import functional as F
import torch
a = F.one_hot(torch.tensor([1,2,3]), num_classes=5)
print(a)
tensor([[0, 1, 0, 0, 0],
[0, 0, 1, 0, 0],
[0, 0, 0, 1, 0]])
#如何快速构造one-hot向量
from torch.nn import functional as F
import torch
a = F.one_hot(torch.tensor([1,2,3]), num_classes=5)
print(a)
tensor([[0, 1, 0, 0, 0],
[0, 0, 1, 0, 0],
[0, 0, 0, 1, 0]])