Python 运行时警告:最大值遇到无效值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15192637/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 19:28:32  来源:igfitidea点击:

RuntimeWarning: invalid value encountered in maximum

pythonnumpyruntime-errormaxnan

提问by green diod

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

numpy 中的奇怪行为(错误??)。与文档相反,下面的代码给出了一个 RuntimeWarning: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)

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)

我被困住了,因为我需要在我的数组中使用这些 NaN,现在我的函数在 iPython 中停止并发出这个该死的警告(好吧,它们真的没有停止,但很烦人)

EDIT:

编辑

numpy 1.6.1

麻木 1.6.1

ipython 0.13.1

蟒蛇0.13.1

采纳答案by tyleha

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 cis still returned in the above code, so it's working fine.

我也遇到同样的问题。这些警告是 numpy 的一个有意方面,用于在用户可能遇到框架的某些限制时通知用户。c上面的代码中仍然返回了的值,所以它工作正常。

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

如果您不想再看到这些特定错误,只需根据需要修改 numpy 的警告设置:

np.seterr(invalid='ignore')

And you won't see invalid value warnings anymore.

您将不会再看到无效值警告。