[Numpy-discussion] Zero Division not handled correctly?
Skipper Seabold
jsseabold@gmail....
Sun Dec 6 15:16:08 CST 2009
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.
Skipper
More information about the NumPy-Discussion
mailing list