efficent test for array with only one value?

Kyler Laird Kyler at news.Lairds.org
Mon Jan 19 01:12:06 CET 2004


I'm trying to discover if there's an efficient way to determine
if all of the values of a Numeric array are the same.  In C, I
would search from the second value, checking each against the
first value.  The first one that doesn't match would trigger a
False return value.  If the loop completes, True would be
returned.

Looking through array functions, I'm not finding anything like
that.  I'm imagining that there should be something like an
equal function (Is that Lisp I'm recalling?) that performs
	a[0,0] == a[0,1] == a[0,2] == ...
and returns False as soon as it is known.  I don't see that.

I can, of course, iterate through all of the values, but it
seems like there should be an efficient built-in function to do
it.

Thank you.

--kyler



More information about the Python-list mailing list