[Numpy-discussion] converting nan to an integer

joep josef.pktd@gmail....
Sat Oct 4 09:31:21 CDT 2008


Why does converting nan to an integer not throw an exception (as with
inf), instead numpy silently replaces nan by zero?


>>> inti = np.array([0,1,2])
>>> inti.dtype
dtype('int32')
>>> inti[1] = np.inf
Traceback (most recent call last):
  File "<pyshell#34>", line 1, in ?
    inti[1] = np.inf
OverflowError: cannot convert float infinity to long
>>> inti[1] = np.nan
>>> inti
array([0, 0, 2])

This is based on an example in numpy.stats.distribution.py

Josef


More information about the Numpy-discussion mailing list