[SciPy-dev] Arrays as truth values?

Steven H. Rogers steve at shrogers.com
Mon Nov 7 21:01:49 CST 2005


OK.  I can't think of a really good use case for using an array as a truth 
value.  I would argue though, that it would make sense for an array of zeros 
to be False and an array with any non-zero values to be True.

Travis Oliphant wrote:
> 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
> 
> _______________________________________________
> Scipy-dev mailing list
> Scipy-dev at scipy.net
> http://www.scipy.net/mailman/listinfo/scipy-dev
> 
> 

-- 
Steven H. Rogers, Ph.D., steve at shrogers.com
Weblog: http://shrogers.com/weblog
"He who refuses to do arithmetic is doomed to talk nonsense."
-- John McCarthy




More information about the Scipy-dev mailing list