[Numpy-discussion] Counting array elements
Chris Barker
Chris.Barker at noaa.gov
Fri Oct 22 15:12:01 CDT 2004
Todd Miller wrote:
> By default, sum() now uses the maximum type of the type family of the
> array, so families Bool, Integer, UnsignedInteger, Float, or Complex
> result in max types Bool, Int64, UInt64, Float64, Complex64. I'm not
> sure why we segregated Bool and it looks like a mistake to me now. I'm
> thinking the Bool "family" should just go away and be re-classified as
> UnsignedInteger.
Well, I think that the idea of a bool being different than an int is
often useful. In this case, we want Bool to behave like an integer, so
that we can use some version of sum() to add up all the true values.
This is handy, but maybe we need more complete support for boolean
arrays, rather than getting rid of them. For instance, there could be a
NumTrue() function or method, for this case. I would probably maintain
the easy conversion of a Bool array to an Int array, for when you really
do need to do math with them.
We'd want a compete set, many of which already exist. A few off the top
of my head:
sometrue
alltrue
numtrue
Maybe mirrors for false:
somefalse
allfalse
numfalse
What else would be needed? My vote would be for all of these to be
methods of a Bool array, but I'm partial to methods over functions anyway.
On the other hand, Python itself is sub classing Bool from integer, so
maybe there's little point.
-Chris
--
Christopher Barker, Ph.D.
Oceanographer
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker at noaa.gov
More information about the Numpy-discussion
mailing list