【问题标题】:module 'torch' has no attribute 'nan_to_num'模块“火炬”没有属性“nan_to_num”
【发布时间】:2021-09-22 07:34:38
【问题描述】:

我在 Ubuntu 上使用 1.7.1 版本的 Pytorch,我尝试执行以下操作:

x = torch.tensor([float('nan'), float('inf'), -float('inf'), 3.14])
torch.nan_to_num(x)

但我收到此错误:

AttributeError: module 'torch' has no attribute 'nan_to_num'

但它确实存在于文档中,因为我只是从中复制了这两行。有人可以帮我吗?

【问题讨论】:

  • nan_to_num 适用于 1.8+
  • 更新 Pytorch,然后重试

标签: python pytorch attributeerror


【解决方案1】:

nan_to_num 是在 PyTorch 1.8 中引入的。您需要更新您的 torch 包才能访问它:

pip install --upgrade torch

【讨论】:

    猜你喜欢
    • 2022-06-27
    • 2023-04-04
    • 2021-05-13
    • 2018-10-10
    • 2018-11-19
    • 2021-12-23
    • 2018-04-29
    • 2020-02-09
    相关资源
    最近更新 更多