[Numpy-discussion] Understanding np.min behaviour with nan

Andrew Nelson andyfaff at gmail.com
Wed Jan 10 17:58:41 EST 2018

I'm having some trouble understanding the behaviour of np.min when used
with NaN. In the documentation of np.amin it says: "NaN values are
propagated, that is if at least one item is NaN, the corresponding min
value will be NaN as well. ". It doesn't say that in some circumstances
there will be RuntimeWarning's raised (presumably depending on the
errstate). Consider the following:

>>> import numpy as np
>>> np.min([1, np.nan])
RuntimeWarning: invalid value encountered in reduce
  return umr_minimum(a, axis, None, out, keepdims)
>>> np.min([1, 2, np.nan])
>>> np.min([np.nan, 1, 2])
>>> np.min([np.nan, 1])

Why is there a RuntimeWarning for the first example, but not the others? Is
this expected behaviour?

Dr. Andrew Nelson

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20180111/60482878/attachment.html>

More information about the NumPy-Discussion mailing list