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

Christopher Ball ceball@gmail....
Tue Mar 13 04:10:04 CDT 2007


> Thank you both for your replies - the difference is clear to me now.


Actually, sorry, I'm still confused!


If I want to be able to have a/0 be inf (for a!=0), then why does that 
stop 0/0 from being nan?

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?


I'm not at all knowledgeable in this area - I'm not requesting any 
changes, just some more explanation.


Thanks again,
Chris




More information about the Numpy-discussion mailing list