[SciPy-dev] Arrays as truth values?

Travis Oliphant oliphant at ee.byu.edu
Thu Nov 10 14:35:17 CST 2005

>I'm not quite sure how any() is supposed to work; does it just return
>true if one or more element evaluates to true?
Yes.  Exactly.  There is an axis argument, but for just testing truth of 
anything in the array you don't want to use it.

>In my current code, I have the following:
>if sum(lower>=median or median>=upper): <do something>
>which returns a ValueError. What is the best way to detect elements in
>one array that are less than the corresponding element in the other
>without constructing a list comprehension?
The ValueError was just recently added because it is ambiguous as to 
what you meant by this.

I would say

if any(lower>=media) or any(median>=upper):  <do something>


More information about the Scipy-dev mailing list