[Numpy-discussion] Zero Division not handled correctly?

David Goldsmith d.l.goldsmith at gmail.com
Tue Dec 8 03:51:11 EST 2009


Thanks, Dave!

DG

On Tue, Dec 8, 2009 at 12:04 AM, David Cournapeau <cournape at gmail.com>wrote:

> On Mon, Dec 7, 2009 at 6:16 AM, Skipper Seabold <jsseabold at gmail.com>
> wrote:
> > I believe this is known, but I am surprised that division by "integer"
> > zero results in the following.
> >
> > In [1]: import numpy as np
> >
> > In [2]: np.__version__
> > Out[2]: '1.4.0.dev7539'
> >
> > In [3]: 0**-1 # or 0**-1/-1
> >
> ---------------------------------------------------------------------------
> > ZeroDivisionError                         Traceback (most recent call
> last)
> >
> > /home/skipper/school/Data/ascii/numpy/<ipython console> in <module>()
> >
> > ZeroDivisionError: 0.0 cannot be raised to a negative power
> >
> > In [4]: np.array([0.])**-1
> > Out[4]: array([ Inf])
> >
> > In [5]: np.array([0.])**-1/-1
> > Out[5]: array([-Inf])
> >
> > In [6]: np.array([0])**-1.
> > Out[6]: array([ Inf])
> >
> > In [7]: np.array([0])**-1./-1
> > Out[7]: array([-Inf])
> >
> > In [8]: np.array([0])**-1
> > Out[8]: array([-9223372036854775808])
> >
> > In [9]: np.array([0])**-1/-1
> > Floating point exception
> >
> > This last command crashes the interpreter.
> >
> > There have been some threads about similar issues over the years, but
> > I'm wondering if this is still intended/known or if this should raise
> > an exception or return inf or -inf.  I expected a -inf, though maybe
> > this is incorrect on my part.
>
> The crash is fixed, but you get some potentially spurious warning,
> still. A thorough solution will require some more work.
>
> David
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20091208/1c5bf5da/attachment.html>


More information about the NumPy-Discussion mailing list