10

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

3
  • 2
    What version? I just tried your code, and didn't get a warning
    – lxop
    Mar 4, 2013 at 0:34
  • Oh, and I'm running 1.6.2
    – lxop
    Mar 4, 2013 at 0:40
  • This install is a EPD install on a Win7 box. numpy 1.6.1-3, ipython 0.13.1-2. I also have no more warning on a box with numpy 1.7.0 and ipython 0.13.1 ... Maybe the 1.6.1 is buggy ..
    – green diod
    Mar 4, 2013 at 1:16

1 Answer 1

15

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.

1
  • 12
    If you know the exact line that this error will be thrown, using the numpy context manager with np.errstate(invalid='ignore'): is probably a safer alternative.
    – Erik
    Jun 24, 2016 at 17:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.