[SciPy-dev] Arrays as truth values?

Travis Oliphant oliphant at ee.byu.edu
Tue Nov 8 19:05:06 CST 2005


Ryan Gutenkunst wrote:

>On Nov 8, 2005, at 10:35 AM, Perry Greenfield wrote:
>  
>
>>Robert has already pointed out that lots of people want == to result in
>>an array of booleans (most I'd argue) rather than a single boolean
>>value.
>>    
>>
>
>I'm coming late to this discussion, but I'd like to mention that a 
>similar issue with the old scipy burned me just today.
>
>Guido's PEP 8 Style Guide suggests:
>     - For sequences, (strings, lists, tuples), use the fact that empty
>       sequences are false, so "if not seq" or "if seq" is preferable
>       to "if len(seq)" or "if not len(seq)".
>
>However, an old scipy array containing any number of zeros is 'False', 
>as illustrated below. (I haven't tried this on new scipy.)
>
> >>> scipy.__version__
>'0.3.3_303.4601'
> >>> if [0]:
>...  print 'hello'
>...
>hello
> >>> if scipy.array([0, 0]):
>...  print 'hello'
>...
> >>>
>  
>
So, do we want empty arrays to return false and not return an error?  
This is definitely a possibility.

-Travis




More information about the Scipy-dev mailing list