1

Consider this simple evaluation:

import numpy as np

aa = np.array([[np.nan, np.nan], [1.64, 0.0784]]) 
bb = [[np.nan, np.nan], [1.64, 0.0784]]

np.all(aa == bb)

This returns False, even though the aa array is equal to the bb list. If I try this for each element in aa, bb I get:

np.all(aa[0] == bb[0])
False
np.all(aa[1] == bb[1])
True

Which means the nan values are the issue here. Why is this happening?

Prune
  • 76,765
  • 14
  • 60
  • 81
Gabriel
  • 40,504
  • 73
  • 230
  • 404

1 Answers1

2

By definition, nan compared to anything (using built-in operands) returns False. In particular, np.nan == np.nan returns False.

Note, however, that != is defined as the negation of ==, so we get:

>>> import numpy as np
>>> np.nan == np.nan
False
>>> np.nan != np.nan
True

You can check directly using

>>> np.isnan(np.nan)
True
Prune
  • 76,765
  • 14
  • 60
  • 81