[SciPy-user] possible to get INF in divide by zero ?

Pauli Virtanen pav at iki.fi
Fri Aug 29 15:29:11 EDT 2008


Fri, 29 Aug 2008 12:23:33 +0000, Pauli Virtanen wrote:

> Thu, 28 Aug 2008 09:56:36 +0200, Stef Mientki wrote:
>> another observation:
>> 
>>  >>> a=numpy.array([2,3])
>>  >>> a/0
>> array([0, 0])
> 
> Division in Numpy preserves the data types: in this case you have an
> integer array divided by an integer, so the output is also an integer.
> 
> But Inf is not one of integers so something must be substituted; and it
> is zero. There probably was some reason for this choice...

Matlab substitutes MAXINT here:

>> x = zeros([2,2],'int32')
>> 1./x

ans =

  2147483647  2147483647
  2147483647  2147483647


I don't know the rationale behind the choice 0 in Numpy...

-- 
Pauli Virtanen




More information about the SciPy-User mailing list