将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)

参考链接

  1. https://www.cnblogs.com/ltkekeli1229/p/15572377.html
posted @ 2024-01-15 16:49  芋圆院长  阅读(15)  评论(0编辑  收藏  举报