[SciPy-user] question about logical "and" and ndarray in Scipy
Michael_OKeefe at nrel.gov
Tue Nov 22 17:02:49 CST 2005
I have a question of the logical 'and' as it relates to ndarray s and whether what I'm seeing is a bug or not. I just upgraded to the latest scipy (as shown below) on a WindowsXP system and found a piece of code that worked previously (essentially line 5 below) but now gives an error.
After a little digging, I found that using an '==' would be equivalent to the 'and' I had wanted to use. However, just curious if the syntax in line 5 should have worked as well.
>>> import scipy
>>> idx = scipy.where( (a>2) and (a<5), 1, 0 )
Traceback (most recent call last):
File "<pyshell#80>", line 1, in -toplevel-
idx = scipy.where( (a>2) and (a<5), 1, 0 )
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
>>> idx = scipy.where( (a>2)==(a<5), 1, 0 )
array([0, 0, 1, 1, 0, 0])
Thanks in advance,
More information about the SciPy-user