[SciPy-user] truth testing new numpy arrays

Paul Ray Paul.Ray at nrl.navy.mil
Tue Jan 31 13:10:03 CST 2006


On Jan 31, 2006, at 10:43 AM, Travis Oliphant wrote:

> I typically use None for optional array arguments.
>
> But, you could do what your doing and test
>
> if any(myvect):
>     <do something>
> else:
>     <do something else>
>
> But, I think the None test is less prone to error.

Assuming you use None for unset optional arguments, how do  you do  
the test?

if myvect:
	<do something>
doesn't work because it is ambiguous if myvect isn't none.

if myvect.any():
	<do something>
doesn't work because None doesn't have an any() method

So, do you use:
if any(myvect):
	<do something>
or,
if myvect is not None:
	<do something>
?

-- Paul

--
Dr. Paul S. Ray              E-mail: Paul.Ray at nrl.navy.mil
Naval Research Laboratory    WWW   : http://xweb.nrl.navy.mil/ 
personnel/paulr/
Code 7655                    Phone : (202) 404-1619
Washington, DC 20375         AIM   : NRLPSR




More information about the SciPy-user mailing list