【发布时间】:2020-04-16 17:56:29
【问题描述】:
我有一个变量a,它是一堆这样的张量:
[tensor([0.0014, 0.0021, 0.0015, 0.0007, 0.0012, 0.0024, 0.0021, 0.0019, 0.0010,
0.0010])]
[tensor([0, 0, 0, 0, 0, 0, 0, 0, 0, 0])]
....
当我想在我的代码中执行此操作时:
x = torch.tensor(a, dtype=torch.float)
我收到了这个错误:
ValueError: only one element tensors can be converted to Python scalars
我假设我可能需要像这样转换a 中的每个张量:
[tensor([[0.0014], [0.0021], [0.0015], [0.0007], [0.0012], [0.0024], [0.0021], [0.0019], [0.0010],
[0.0010]])]
[tensor([[0], [0], [0], [0], [0], [0], [0], [0], [0], [0]])]
我的想法对吗?或者我需要什么来避免上述错误?
有什么帮助吗?
【问题讨论】: