【问题标题】:can't convert pytorch tensor dtype from float64 to double无法将 pytorch 张量 dtype 从 float64 转换为 double
【发布时间】: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)

关于它为什么不转换的任何想法?

【问题讨论】:

    标签: python pytorch


    【解决方案1】:

    它正在转换; torch.float64torch.doublesame thing

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-01-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-17
      • 2022-10-17
      • 2016-06-14
      • 1970-01-01
      相关资源
      最近更新 更多