I just find this a bit strange tbh. Environment is Python v3
and while it looks fine to me for the expression
import numpy as np
np.nan==np.nan
to return False
when used in a tuple:
(np.nan,)==(np.nan,)
it returns True
I just find this a bit strange tbh. Environment is Python v3
and while it looks fine to me for the expression
import numpy as np
np.nan==np.nan
to return False
when used in a tuple:
(np.nan,)==(np.nan,)
it returns True
As mentioned in the numpy documentation:
np.nan == np.nan # is always False! Use special numpy functions instead.
I assume that upon comparing tuples, values are being checked one after another, but check behind the scene is different than explicit comparison, especially for ==
check.
For instance, check occurs by comparing id(elem) values, which must be the same for two different numpy.nan, therefore it returns true. Also, most likely, on the non cpython implementations the result may be false to, due to internal optimizations for storing values of variables.
Additionaly, you may checkout magic implementation of numpy.nan
which may give you more glue of what is going on behind the scene on comparison action.