[Numpy-discussion] Division by zero doesn't raise exception in the integer case.

Travis Oliphant oliphant at ee.byu.edu
Tue Sep 19 18:13:54 CDT 2006


Charles R Harris wrote:

> Travis,
>
> Is this intentional?
>
> In [77]: arange(5, dtype=int)/0
> Out[77]: array([0, 0, 0, 0, 0])
>
> It looks deliberate because all zeros are returned, but it might be 
> better if it raised an exception.


It is deliberate.   Numarray introduced it (the only difference being 
that by default NumPy has division-by-zero erros turned off). It's tied 
to the way floating-point division-by zero is handled.   There is a 
valid argument for having a separate integer-division flag so that you 
can raise exceptions for integer-division but not for floating-point 
division.  I'm open to that change for 1.0rc1

-Travis





More information about the Numpy-discussion mailing list