首页 > 解决方案 > 模块“火炬”没有属性“nan_to_num”

问题描述

我在 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'

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

标签: pythonpytorchattributeerror

解决方案


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

pip install --upgrade torch

推荐阅读