将array转化为tensor,再转化为独热编码
# 将向量转化为tensor编号,并转化为独热编码
m = np.array([0, 1,2,3,4])
x = torch.Tensor(m)
print(x)
b = F.one_hot(x.unsqueeze(0).to(torch.int64), 5)
print(b)
# 将向量转化为tensor编号,并转化为独热编码
m = np.array([0, 1,2,3,4])
x = torch.Tensor(m)
print(x)
b = F.one_hot(x.unsqueeze(0).to(torch.int64), 5)
print(b)