Assign NaN, get zero

Keith Goodman kwgoodman at gmail.com
Sat Nov 11 12:40:22 CST 2006


I accidentally wrote a unit test using int32 instead of float64 and
ran into this problem:

>> x = M.matrix([[1, 2, 3]])
>> x[0,1] = M.nan
>> x
matrix([[1, 0, 3]])   <--- Got 0 instead of NaN

But this, of course, works:

>> x = M.matrix([[1.0, 2.0, 3.0]])
>> x[0,1] = M.nan
>> x
matrix([[ 1.        ,         nan,  3.        ]])

Is returning a 0 instead of NaN the expected behavior?

If so do I need to check dtype before inserting NaNs? And if the dtype
is int32, then raise an exception?

I'm using 1.0rc1 from debian etch.

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642




More information about the Numpy-discussion mailing list