RuntimeWarning:最大遇到无效值 [英] RuntimeWarning: invalid value encountered in maximum

查看:106
本文介绍了RuntimeWarning:最大遇到无效值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

numpy中有奇怪的行为(错误?).与文档相反,以下代码给出了RuntimeWarning:在fmax中遇到无效值

Weird behavior (bug??) in numpy. Contrary to the docs, the following code gives a RuntimeWarning: invalid value encountered in fmax

a = np.random.uniform(0.1, 0.4, (5, 5))
b = np.random.uniform(0, 3.5, (5, 5))
b[0, 0] = np.nan

c = np.fmax(a, b) # Same problem with c = np.maximum(a, b)

我陷入困境,因为我的数组中需要这些NaN,现在我的函数在该死的警告中停止在iPython中(好吧,它们确实不会停止,但是很烦人)

I'm stuck as I need these NaNs in my arrays and now my functions stop in iPython with this damn warning (ok, they really don't stop but it's rather annoying)

编辑:

numpy 1.6.1

numpy 1.6.1

ipython 0.13.1

ipython 0.13.1

推荐答案

我也遇到了同样的问题.这些警告是numpy的故意方面,用于在用户可能遇到框架某些限制的情况下通知用户.上面的代码中仍返回c的值,因此可以正常工作.

I get the same issue as well. These warnings are an intentional aspect of numpy, to inform users when they may be running up against some limitations of the framework. The value of c is still returned in the above code, so it's working fine.

如果您不想再看到这些特定的错误,只需使用以下命令修改numpy的警告设置:

If you don't want to see these specific errors anymore, just modify numpy's warning settings as you wish with:

np.seterr(invalid='ignore')

您将不再看到无效的值警告.

And you won't see invalid value warnings anymore.

这篇关于RuntimeWarning:最大遇到无效值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆