[SciPy-User] [SciPy-user] ValueError: The truth value of an array with more than one element is ambiguous.
Thu Apr 5 23:54:40 CDT 2012
On Thu, Apr 5, 2012 at 6:46 PM, surfcast23 <firstname.lastname@example.org> wrote:
> Hi, I have an if statement and what I want it to do is go through arrays
> and find the common elements in all three arrays. When I try the code below
> I get this error * ValueError: The truth value of an array with more than
> one element is ambiguous. Use a.any() or a.all()* Can some one explain
> the error to me and how I might be able to fix it. Thanks in advance. *if
> min <= Xa <=max & min <= Ya <=max & min <= Za <=max: print("in range")
> else: print("Not in range")*
This explanation may or may not be clear, but your question is answered in
1) Python's default behavior for chained comparisons don't work as you'd
expect for numpy arrays.
2) Python doesn't allow numpy to change this default behavior (at least
currently, and maybe
Nevertheless, you can get around this by separating the comparisons
>>> if (min <= Xa) & (Xa <= max):
Note the use of `&` instead of `and`, which is at the heart of the
Hope that helps,
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the SciPy-User