[Numpy-discussion] 0/0 == 0?

Charles R Harris charlesr.harris at gmail.com
Thu Oct 2 19:29:42 EDT 2014


On Thu, Oct 2, 2014 at 5:02 PM, T J <tjhnson at gmail.com> wrote:

> Hi, I'm using NumPy 1.8.2:
>
> In [1]: np.array(0) / np.array(0)
> Out[1]: 0
>
> In [2]: np.array(0) / np.array(0.0)
> Out[2]: nan
>
> In [3]: np.array(0.0) / np.array(0)
>                                                             Out[3]: nan
>
> In [4]: np.array(0.0) / np.array(0.0)
> Out[4]: nan
>
>
> In [5]: 0/0
> ---------------------------------------------------------------------------
> ZeroDivisionError                         Traceback (most recent call last)
> <ipython-input-6-6549dea6d1ae> in <module>()
> ----> 1 0/0
>
> ZeroDivisionError: integer division or modulo by zero
>
>
>
> Out[1] seems odd. I get the right value in 1.8.1.  Was this fixed for
> 1.9.0?
>
>
In master on Fedora I get

In [1]: np.array(0) / np.array(0)
/home/charris/.local/bin/ipython:1: RuntimeWarning: divide by zero
encountered in divide
  #!/usr/bin/python
Out[1]: 0

Note that the warning is only given once, it's a warnings module thing.

In [2]: np.array(0) / np.array(0)
Out[2]: 0

And it might even be system dependent.

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20141002/f02e0911/attachment.html>


More information about the NumPy-Discussion mailing list