efficent test for array with only one value?

Kyler Laird Kyler at news.Lairds.org
Mon Jan 19 23:12:09 EST 2004


Robert Kern <rkern at ucsd.edu> writes:

> >>> from Numeric import *
> >>> a = ones((3,5))
> >>> equal.reduce(a.flat)
>1
> >>> a[0,3] = 0
> >>> equal.reduce(a.flat)
>0
> >>>

>Ufuncs are wonderful things.

Yeah, but they also don't work for this.  First, I'm guessing that reduce
will not stop immediately when equal encounters a False.  (It doesn't do
"and".)

Also, it just plain doesn't work.
	>>> import Numeric
	>>> a = Numeric.zeros((3,5))
	>>> Numeric.equal.reduce(a.flat)
	0
	>>> Numeric.equal.reduce([0,0,0,0,0,0,1])
	1

--kyler



More information about the Python-list mailing list