0

If I compare two array which contain NaNs like so:

a = np.array([[1,2,3], [np.nan, 2, 3]])
b = np.array([[1,2,3], [np.nan, 2, 3]])
np.where(a==b, a, -1)

I get

 array([[ 1.,  2.,  3.],
       [-1.,  2.,  3.]])

which makes sense because:

np.nan == np.nan

yields False

However, np.where(a is b, a, -1) does not make sense either.

np.allclose(a, b, 1e-5)

yields False

Since bith arrays have the same values, how can I prove that?

Moritz
  • 5,130
  • 10
  • 40
  • 81
  • Also, relevant - numpy.testing.assert_almost_equal. – Divakar Nov 26 '19 at 09:49
  • When trying understand this `where`, make sure you understand the first, condition argument (by itself). `a==b` and `a is b` test two very different things. – hpaulj Nov 26 '19 at 12:08

0 Answers0