[SciPy-user] Array functions

Howey, David A d.howey at imperial.ac.uk
Mon Aug 8 06:12:48 CDT 2005

I guess this is a numpy question, but how do I do truth tests on arrays?
I'm trawling around the documentation but struggling to find an answer..

I want to test if any array contains ONLY zeros.

Originally I had:
 if a == 0:
	# code in here

I need this to be true both for 
a = 0 # ie a is just a number

and for
a = array((0,0,0,0,0))

It must return false for any array with any nonzero elements anywhere

At the moment python does this (which is wrong):

>>> vin = array((1.,0,0))
>>> vin
array([ 1.,  0.,  0.])
>>> if vin == 0: print "yes"




More information about the SciPy-user mailing list