I ran into an unpredicted behavior with Python's Numpy, set and NaN (not-a-number):
>>> set([np.float64('nan'), np.float64('nan')])
set([nan, nan])
>>> set([np.float32('nan'), np.float32('nan')])
set([nan, nan])
>>> set([np.float('nan'), np.float('nan')])
set([nan, nan])
>>> set([np.nan, np.nan])
set([nan])
>>> set([float('nan'), float('nan')])
set([nan, nan])
Here np.nan yields a single element set, while Numpy's nans yield multiple nans in a set. So does float('nan')! And note that:
>>> type(float('nan')) == type(np.nan)
True
I wonder how this difference come about and what the rationality is behind the different behaviors.
See Question&Answers more detail:os