0
>>> a=np.array([[1,2,3],[3,np.nan,9]])
>>> a
array([[  1.,   2.,   3.],
       [  3.,  nan,   9.]])
>>> print a[1][1]
nan
>>> a[1][1]==np.nan
False
>>> np.isnan(a[1][1])
True

Can somebody explain the result for me? why the "a[1][1]==np.nan" returns False but the np.isnan(a[1][1]) returns True? Thanks in advance!

John Coleman
  • 51,337
  • 7
  • 54
  • 119
Statham
  • 4,000
  • 2
  • 32
  • 45
  • 1
    It's just the way that NaN is defined in a IEEE standard - NumPy follows the convention that NaN is not equal to itself. – Alex Riley Dec 18 '16 at 14:35
  • (Also, it's better to use `a[1, 1]` for indexing here instead of `a[1][1]`); you can specify indices/slices for multiple dimensions at the same time when using NumPy arrays.) – Alex Riley Dec 18 '16 at 14:42

0 Answers0