As far as I understand it, ==
checks for equality of value, and is
checks for identity of structure behind value (as, say ===
in some other languages).
Given that, I don't understand the following:
np.isnan(30) == False
Out[19]:
True
np.isnan(30) is False
Out[20]:
False
It appears not to be the case with other identity checks:
(5 == 4) == False
Out[22]:
True
(5 == 4) is False
Out[23]:
True
It appears as if np.isnan()
returns False
as a value, but not as identity. Why is that the case?
numpy.isnan()
returns a compatible type object:This is a custom boolean that can be stored efficiently in numpy arrays, see Numpy's Data Types documentation. The
numpy.isnan()
function can also operate on arrays, producing another array with results:where again the
dtype
is the Numpy boolean object.Python makes no guarantees that boolean operations must always return a singleton boolean value. You should never test for
is True
oris False
anyway. Usenumpy.isnan()
output directly in boolean operations, usenot
to test for false values:and
np.isnan(30)
return
snp.False_
which has a different identity fromFalse
; don't rely on this though.