I am trying to compare two different lists to see if they are equal, and was going to remove NaNs, only to discover that my list comparisons still work, despite NaN == NaN -> False
.
Could someone explain why the following evaluate True
or False
, as I am finding this behavior unexpected. Thanks,
I have read the following which don't seem to resolve the issue:
- Why in numpy
nan == nan
is False while nan in [nan] is True? - Why is NaN not equal to NaN? [duplicate]
(Python 2.7.3, numpy-1.9.2)
I have marked surprising evaluations with a *
at the end
>>> nan = np.nan
>>> [1,2,3]==[3]
False
>>> [1,2,3]==[1,2,3]
True
>>> [1,2,nan]==[1,2,nan]
True ***
>>> nan == nan
False
>>> [nan] == [nan]
True ***
>>> [nan, nan] == [nan for i in range(2)]
True ***
>>> [nan, nan] == [float(nan) for i in range(2)]
True ***
>>> float(nan) is (float(nan) + 1)
False
>>> float(nan) is float(nan)
True ***