我需要将int转换为双张量,并且我已经尝试过几种方法,包括torch.tensor([x], dtype=torch.double),首先定义张量,然后用x_tensor.double()将dtype转换为double,还有用torch.DoubleTensor([x])定义张量,但实际上没有人从torch.float64更改dtype。这是代码片段
>>> 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)对它为什么不转化有什么想法吗?
发布于 2021-02-26 19:05:26
它正在转换;torch.float64和torch.double是同样的事情
https://stackoverflow.com/questions/66391304
复制相似问题