Why does assert np.nan == np.nan throw an error?
2 answers
NaN
has the property that it is not equal to itself, you should use np.isnan
to test the values NaN
here np.isnan(np.nan)
will give True
:
In[5]:
np.nan == np.nan
Out[5]: False
In[6]:
np.nan != np.nan
Out[6]: True
In[7]:
np.isnan(np.nan)
Out[7]: True
As noted by Lukasz Rogalski, the is
following will also work:
In [10]: np.nan is np.nan
Out[10]: True
+8
source to share