一串里面只有一个1,其他都是0
numpy转onehot编码
Python的一些库和函数_hxxjxw的博客-CSDN博客_python库和函数
pytorch转onehot编码
Pytorch(一) —— 相关库和函数_hxxjxw的博客-CSDN博客_pytorch库函数
法2
target_classes_onehot = torch.zeros([src_logits.shape[0], src_logits.shape[1], src_logits.shape[2]+1], dtype=src_logits.dtype, layout=src_logits.layout, device=src_logits.device) target_classes_onehot.scatter_(2, target_classes.unsqueeze(-1), 1)
one-hot encoding 独热表示/独热编码(onehot)
于 2020-05-13 23:25:18 首次发布