1

What happens when I compare an integer or float with np.nan in python?

5 < np.nan?
np.nan > 100?

I ran those commands myself and got False every time. Is this a consistent behavior?

roger
  • 1,091
  • 1
  • 7
  • 15
lostboy_19
  • 13
  • 2
  • Possible duplicate of [inequality comparison of numpy array with nan to a scalar](http://stackoverflow.com/questions/25345843/inequality-comparison-of-numpy-array-with-nan-to-a-scalar) – Nick T Feb 22 '17 at 18:16
  • 1
    yes. if you want to see if the value of a variable is actually NaN, use `np.isnan`. See also, `np.isfinite`. – Paul H Feb 22 '17 at 18:16

1 Answers1

1

Yes this is correct. As a matter of fact, the way that np.nan is written, you'll also get False if you try np.nan == np.nan or np.nan = None. As stated in the comments, you should use np.isnan instead.

Некто
  • 1,730
  • 10
  • 17