[SciPy-dev] Arrays as truth values?

Travis Oliphant oliphant at ee.byu.edu
Tue Nov 1 10:06:33 CST 2005


Perry Greenfield wrote:

>The recent question about use of "and" and "or" highlighted an issue I 
>think is worth at least a little discussion (I don't recall it being 
>discussed for scipy_core, but maybe it already has been).
>
>  
>
It's a good discussion to have.  I don't recall talking about it.

>numarray doesn't permit using arrays as truth values since we figured 
>that it wasn't very clear what people expected to happen (this case is 
>a good illustration). I'd like to make the argument that scipy_core 
>also not permit arrays to be used as truth values (i.e., one should get 
>an exception if one tries to use it that way). I realize that this will 
>break some old code, but since incompatible changes are being made, 
>this is the time to make this sort of change.  If left in, it is going 
>to bite people, often quietly.
>
>  
>
I agree it can bite people, but I'm concerned that arrays not having a 
truth value is an odd thing in Python --- you have to implement it by 
raising an error when __nonzero__ is called right?

All other objects in Python have truth values (including its built-in 
array).  My attitude is that its just better to teach people the proper 
use of truth values, then to break form with the rest of Python.

I'm would definitely like to hear more opinions though.  It would be 
very easy to simply raise and error when __nonzero__ is called.

-Travis




More information about the Scipy-dev mailing list