python - 模块“火炬”没有属性“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'
但它确实存在于文档中,因为我只是从中复制了这两行。有人能帮我吗 ?
解决方案
nan_to_num
在 PyTorch 1.8中引入。您需要更新您的手电筒包才能访问它:
pip install --upgrade torch
推荐阅读
- .net - 如何从 VB.NET 中的 XML 文件构建唯一的树结构
- javascript - 在 HTML 中,如何创建一个内容超出边框且可拖动的 div?
- html - 特定区域的背景颜色
- postgresql - PSQL \copy 从带有 QUOTE 的 bash 脚本
- sql-server - SQL Server 如何锁定行?
- javascript - Slick Slider - 从另一个页面创建链接
- mysql - 相关表有别名时如何按关系排序
- javascript - 在汇总构建中包含特定模块
- svelte - Culori js 适用于 Svelte REPL 但不适用于本地项目
- javascript - React JS 路由:从一页中省略一些组件