[SciPy-dev] Arrays as truth values?

Travis Oliphant oliphant at ee.byu.edu
Mon Nov 7 16:54:44 EST 2005


Perry Greenfield wrote:

>Essentially, my argument is that this case presents many likely 
>surprises for users and when there isn't one obvious way to do it, it 
>shouldn't be done. I'd argue that not allowing arrays as truth values 
>it is more Pythonic. (Existing arrays don't support rich comparisons, 
>and they are false only when empty, as would be expected).
>  
>
Right now, I'm leaning towards raising an error.  A big explanation for 
that is the idea that "explicit" is better than "implicit."  I'm 
persuaded by Perry's argument that a casual user is going to think that 
"and" and "&" have the same behavior for arrays.  The experienced user 
is going to understand the difference, anyway. 

So ultimately, I don't really see an impressive use case for returning a 
truth value for arrays, but I do see a "new-user" issue if an error is 
not raised.

So, right now in SVN, arrays as truth values raise erros unless the 
array contains only one element (in which case it is unambiguous). 

-Travis




More information about the SciPy-Dev mailing list