pytorch - Torch C++:检查 NAN 的 API
问题描述
我正在使用 libtorch C++。在 python 版本中,我们可以通过调用张量的值来轻松检查张量的numpy
值,在numpy
我们有np.isnan()
. 我想知道是否有内置函数libtorch
C++
来检查张量是否有任何NAN
价值?
谢谢, 阿夫辛
解决方案
补充法比奥的回答(我的声誉太低,无法评论):
assert
如果你真的想在 an or条件下使用有关 NAN 的信息,if
你需要将它从 a 转换torch::Tensor
为 C++bool
像这样
torch::Tensor myTensor;
// do something
auto tensorIsNan = at::isnan(myTensor).any().item<bool>(); // will be of type bool
推荐阅读
- spring-security - 在 vaadin flow 14 中排除来自 vaadin 路由器的 URL 路径
- python - 谷歌翻译突然停止工作我没有以任何方式更改代码
- python - ModuleNotFoundError(相对于 healpy)
- javascript - Angular - 如何仅绑定函数中的特定项目
- php - 未捕获的错误:找不到类“PHP_Token_ELLIPSIS”
- python - 如何使用python增加字典中的值
- spring-batch - JdbcCurserdReader 的问题它接缝读取正常,但作者获得包含相同项目列表的块
- typescript - 用 RN Detox 模拟
- python - 更快地从 Flask 到 Datatables 的一百万条记录的最佳方法是什么?
- reactjs - 通过 Webpack 导出模块