[Numpy-discussion] Counting array elements

Alan G Isaac aisaac at american.edu
Fri Oct 22 19:17:02 CDT 2004


More new user feedback ...

On Fri, 22 Oct 2004, Chris Barker apparently wrote:
> Well, I think that the idea of a bool being different than
> an int is often useful.

Yes.  E.g., applications to directed graphs.


> we can use some version of sum() to add up all the
> true values.

Unclear, but given the existence of sometrue,
it seems natural enough to let sum treat a Bool as an
integer.  Products work naturally, of course.

> 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.

I would rephrase this.
Boolean arrays have a naturally different math,
which it would be nice to have supported.
It would also be nice to easily convert to Int,
when that representation captures the math needed.

> We'd want a compete set, many of which already exist. A few off the top
> of my head:
> sometrue
> alltrue
> numtrue       

I'd just let sum handle numtrue.

> Maybe mirrors for false:
> somefalse, allfalse, numfalse

I'd just rely on alltrue, sometrue, and (size less sum) for these.

fwiw,
Alan







More information about the Numpy-discussion mailing list