RuntimeWarning: invalid value encountered in maximum

时间秒杀一切 提交于 2019-12-22 04:36:06

问题


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)

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)

EDIT:

numpy 1.6.1

ipython 0.13.1


回答1:


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.

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.



来源:https://stackoverflow.com/questions/15192637/runtimewarning-invalid-value-encountered-in-maximum

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!