Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RuntimeWarning: invalid value encountered in maximum

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

like image 925
green diod Avatar asked Mar 04 '13 00:03

green diod


1 Answers

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.

like image 54
tyleha Avatar answered Oct 14 '22 08:10

tyleha