[Numpy-discussion] 0/0 is 0 or nan?
Christopher Barker
Chris.Barker@noaa....
Fri Mar 9 11:13:49 CST 2007
Robert Kern wrote:
> However, I believe that divide() on two Python ints goes through a different
> path than for numpy arrays and numpy scalars. Rather, they are recognized as
> objects that implement .__div__(), and that is called instead.
Then wouldn't this be different:
>>> a = N.array(0, dtype=N.int)
>>> b = N.array(0, dtype=N.int)
>>> N.divide(a,b)
0
or to really make sure we're not using Python integers:
>>> a = N.array(0, dtype=N.int16)
>>> b = N.array(0, dtype=N.int16)
>>> N.divide(a,b)
0
for completeness:
>>> a = N.array(0, dtype=N.float)
>>> b = N.array(0, dtype=N.float)
>>> N.divide(a,b)
Warning: invalid value encountered in divide
nan
-Chris
--
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker@noaa.gov
More information about the Numpy-discussion
mailing list