[Numpy-discussion] 0/0 is 0 or nan?

Robert Kern robert.kern@gmail....
Tue Mar 13 23:30:17 CDT 2007

Christopher Ball wrote:

> In Python, a/0 gives a divide-by-zero error for any a, but in numpy, I 
> can ignore divide-by-zero errors. If I do this, why can't I still have 
> 0/0 be nan?
> seterr(divide='ignore')
> a=array([0],dtype=float_)
> b=array([0],dtype=float_)
> divide(a,b)
> gives nan, so why doesn't
> seterr(divide='ignore')
> a=array([0],dtype=int_)
> b=array([0],dtype=int_)
> divide(a,b)
> also give nan, rather than 0 as it gives now? Is this because inf is not 
> something to which an int can be set (as Christopher Barker wrote), and 
> it matches Python's behavior?

Pretty much. ints operated with ints will give ints, not floats. nan and inf are
floating point concepts.

Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

More information about the Numpy-discussion mailing list