[Numpy-discussion] More numpy and Numeric differences

Pearu Peterson pearu at scipy.org
Sat Feb 11 09:08:01 EST 2006


I have created a wiki page

   http://scipy.org/PearuPeterson/NumpyVersusNumeric

that reports my findings on how numpy and Numeric behave on various corner 
cases. Travis O., could you take a look at it?
Here is the most recent addition:

"""
Clipping integer array with Inf

In Numeric (v24.2) clip returns float array:

>>> from Numeric import *
>>> Inf = array(1.0)/0
>>> clip([1,2],0,Inf)
array([ 1.,  2.])
>>>

In numpy (v0.9.5.2092) Overflow error is raised:

>>> from numpy import *
>>> clip([1,2],0,Inf)
Traceback (most recent call last):
   File "<stdin>", line 1, in ?
   File "/usr/local/lib/python2.3/site-packages/numpy/core/oldnumeric.py", 
line 336, in clip
     return asarray(m).clip(m_min, m_max)
OverflowError: cannot convert float infinity to long

Comment: is it a numpy bug? Should clip take optional dtype argument and 
return asarray(m, dtype=dtype).clip(m_min, m_max)? Then also array.clip 
should have optional dtype..
"""

Pearu




More information about the NumPy-Discussion mailing list