[Numpy-discussion] why not zerodivision error?

Tony Yu tsyu80 at gmail.com
Sun May 20 12:55:49 EDT 2012


On Sun, May 20, 2012 at 3:47 AM, eat <e.antero.tammi at gmail.com> wrote:

> Hi,
>
> On Sun, May 20, 2012 at 10:21 AM, Chao YUE <chaoyuejoy at gmail.com> wrote:
>
>> Dear all,
>>
>> could anybody give one sentence about this? why in the loop I didn't get
>> zerodivision error by when I explicitly do this, I get a zerodivision
>> error? thanks.
>>
>> In [7]: for i in np.arange(-10,10):
>>         print 1./i
>>    ...:
>> -0.1
>> -0.111111111111
>> -0.125
>> -0.142857142857
>> -0.166666666667
>> -0.2
>> -0.25
>> -0.333333333333
>> -0.5
>> -1.0
>> inf
>> 1.0
>> 0.5
>> 0.333333333333
>> 0.25
>> 0.2
>> 0.166666666667
>> 0.142857142857
>> 0.125
>> 0.111111111111
>>
>> In [8]: 1/0.
>>
>> ---------------------------------------------------------------------------
>> ZeroDivisionError                         Traceback (most recent call
>> last)
>> /mnt/f/data/DROUGTH/<ipython-input-8-7e0bf5b37da6> in <module>()
>> ----> 1 1/0.
>>
>
[snip]


> You may like to read more on here
> http://docs.scipy.org/doc/numpy/reference/generated/numpy.seterr.html#numpy.seterr
>

[snip]


> My 2 cents,
> -eat
>
>>
>>
Also, note that the original errors were raised when working with pure
Python types (ints and floats), while in the loop you were dividing by
numpy scalars, which handles division-by-zero differently.

Best,
-Tony
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20120520/da4c1a6b/attachment.html>


More information about the NumPy-Discussion mailing list