Thu Feb 21 16:07:59 CST 2008
One solution is to do a boolean comparison and then call sum() on the
resulting boolean array. It'll treat the True's as 1's and so you end
up with the number of occurrences.
In : x = array([2,2,2,2,3,4,5,6,7,8])
In : x == 2
Out: array([ True, True, True, True, False, False, False, False,
False, False], dtype=bool)
In : sum(x == 2)
There might be other ways, of course.
On 21-Feb-08, at 5:01 PM, R. Padraic Springuel wrote:
> Is there a numpy or scipy command that works on arrays like the count
> property works on lists?
> I.e. if I want to know how many times a certain value occurs in an
> array, is there a single command that will allow me to do that?
> R. Padraic Springuel
> Research Assistant
> Department of Physics and Astronomy
> University of Maine
> Bennett 309
> Office Hours: By appointment only
> SciPy-user mailing list
More information about the SciPy-user