【发布时间】:2021-02-27 03:05:26
【问题描述】:
我需要将 int 转换为双张量,我已经尝试了几种方法,包括 torch.tensor([x], dtype=torch.double),首先定义张量,然后使用 x_tensor.double() 将 dtype 转换为双精度,并且还使用 @ 定义张量987654323@ 但实际上没有一个从torch.float64 更改dtype。这是代码sn-p
>>> x = 6
>>> x = torch.tensor([x], dtype=torch.double)
>>> x
tensor([6.], dtype=torch.float64)
>>> x = 6
>>> x_tensor = torch.Tensor([x])
>>> x_double = x_tensor.double()
>>> x_double
tensor([6.], dtype=torch.float64)
>>> x_tensor = torch.DoubleTensor([x])
>>> x_tensor
tensor([6.], dtype=torch.float64)
关于它为什么不转换的任何想法?
【问题讨论】: