4 Oct 16:30
converting nan to an integer
From: joep <josef.pktd <at> gmail.com>
Subject: converting nan to an integer
Newsgroups: gmane.comp.python.numeric.general
Date: 2008-10-04 14:31:21 GMT
Subject: converting nan to an integer
Newsgroups: gmane.comp.python.numeric.general
Date: 2008-10-04 14:31:21 GMT
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
RSS Feed