while numpy.nan
not equal numpy.nan
, , (float('nan'), 1)
not equal float('nan', 1)
,
(numpy.nan, 1) == (numpy.nan, 1)
what reason? python first check see if ids identical? if identity checked first when comparing items of tuple, why isn't checked when objects compared directly?
when numpy.nan == numpy.nan
it's numpy deciding whether condition true or not. when compare tuples
python checking if tuples have same objects do. can make numpy
have decision turning tuples
numpy
arrays.
np.array((1, numpy.nan)) == np.array((1,numpy.nan)) >>array([ true, false], dtype=bool)
the reason when ==
numpy
objects you're calling numpy function __eq__()
says nan != nan
because mathematically speaking nan
undetermined (could anything) makes sense nan != nan
. when ==
tuples call tuples __eq__()
function doesn't care mathematics , cares if python objects same or not. in case of (float('nan'),1)==(float('nan'),1)
returns false
because each call of float('nan')
allocates memory in different place can check doing float('nan') float('nan')
.
Comments
Post a Comment