Strange behaviour of Numeric.where
Otto T Hyvarinen
ohyvarin at cc.helsinki.fi
Mon Jun 4 09:05:34 EDT 2001
Perhaps there is a rational explanation to this:
"
Python 2.0 (#5, Feb 20 2001, 11:00:04)
[GCC 2.95.3 19991030 (prerelease)] on linux2
Type "copyright", "credits" or "license" for more information.
>>> import Numeric
>>> a=Numeric.array([1,2,0,4,1])
>>> Numeric.where(Numeric.equal(a,0),0,1/a)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
ZeroDivisionError: divide by zero
>>> Numeric.where(Numeric.equal(a,0),0,1./a)
array([ 1. , 0.5 , 0. , 0.25, 1. ])
>>>
"
The first version is a bit stupid, because it will only return ones and
zeros. But why it returns division by zero is beyond me.
I tried this on Python1.5.2 with Irix, and got the same results except that
with Irix I get:
"
>>> Numeric.where(Numeric.equal(a,42),0,1/a)
array([1, 0, 0, 0, 1])
"
and with Linux:
"
>>> Numeric.where(Numeric.equal(a,42),0,1/a)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
ZeroDivisionError: divide by zero
"
Strange.
Otto Hyvärinen, otto.hyvarinen at fmi.fi
More information about the Python-list
mailing list