博客
关于我
any() missing 1 required positional arguments: "dim"
阅读量:95 次
发布时间:2019-02-26

本文共 657 字,大约阅读时间需要 2 分钟。

在某些情况下,我们可能会遇到如下的错误提示:

TypeError: any() missing 1 required positional arguments: "dim"

这意味着在调用 np.any() 函数时,缺少了一个必要的位置参数 "dim"。以下是一个示例:

scores = torch.linspace(0.5, 0.6, steps=2).view(2)  # b = torch.FloatTensor(0.5).sequnce()  # print(b)

为了避免上述错误,可以按照以下方法进行修改:

scores = torch.linspace(0.5, 0.6, steps=2).view(2)  # b = torch.FloatTensor(0.5).sequnce()  # print(b)
if np.any(scores > 5):
print(111)

解决方法:

为了修复此问题,可以使用以下修改后的代码:

scores = torch.linspace(0.5, 0.6, steps=2).view(2)  # b = torch.FloatTensor(0.5).sequnce()  # print(b)
if np.any(scores > 5):
print(111)

具体来说,修改的内容是:

np.any(np.array(scores > 5))

这样可以更好地检查 scores 是否大于 5。如果有任何值大于 5,会输出 111。

转载地址:http://rlfk.baihongyu.com/

你可能感兴趣的文章
NutUI:京东风格的轻量级 Vue 组件库
查看>>
NutzCodeInsight 2.0.7 发布,为 nutz-sqltpl 提供友好的 ide 支持
查看>>
NutzWk 5.1.5 发布,Java 微服务分布式开发框架
查看>>