From: Sasha <nd...@ma...> - 2006-09-07 20:48:11
|
On 9/7/06, Martin Spacek <sc...@ms...> wrote: > What's the most straightforward way to count, say, the number of 1s or > Trues in the array? Or the number of any integer? > > I was surprised to discover recently that there isn't a count() method > as there is for Python lists. Sorry if this has been discussed already, > but I'm wondering if there's a reason for its absence. > You don't really need count with ndarrays: >>> from numpy import * >>> a = array([1,2,3,1,2,3,1,2]) >>> (a==3).sum() 2 |