[Numpy-discussion] Any and all NaNs

Keith Goodman kwgoodman@gmail....
Fri May 23 12:16:53 CDT 2008

I'm writing unit tests for a module that contains matrices. I was
surprised that these are True:

>> import numpy.matlib as mp
>> x = mp.matrix([[mp.nan]])
>> x.any()
>> x.all()

My use case is (x == y).all() where x and y are the same matrix except
that x contains one NaN. Certianly x and y are not equal.

>> x = mp.asmatrix(range(4)).reshape(2,2)
>> y = mp.asmatrix(range(4)).reshape(2,2)
>> x[0,0] = mp.nan
>> (x == y).all()

More information about the Numpy-discussion mailing list