我有一个问题,需要将Python数字列表转换为PyTorch张量:这是我的代码:
caption_feat = [int(x) if x < 11660 else 3 for x in caption_feat]
打印 caption_feat 的结果是:[1, 9903, 7876, 9971, 2770, 2435, 10441, 9370, 2]
。 我这样进行转换:tmp2 = torch.Tensor(caption_feat)
,现在打印 tmp2 的结果是:tensor([1.0000e+00, 9.9030e+03, 7.8760e+03, 9.9710e+03, 2.7700e+03, 2.4350e+03,
1.0441e+04, 9.3700e+03, 2.0000e+00])
。 然而,我原本期望得到的是:tensor([1. , 9903, , 9971. ......])
。你有什么想法吗?
torch.tensor()
来构建张量。 - dedObed