[Numpy-discussion] Count the occurrence of a certain integer in a list of integers

Matthieu Brucher matthieu.brucher at gmail.com
Tue Aug 7 08:13:49 EDT 2007


You can try using hist() with the correct range and number of bins.

Matthieu

2007/8/7, Nils Wagner <nwagner at iam.uni-stuttgart.de>:
>
> Hi all,
>
> I have a list of integer numbers. The entries can vary between 0 and 19.
> How can I count the occurrence of any number. Consider
>
> >>> data
> [9, 6, 9, 6, 7, 9, 9, 10, 7, 9, 9, 6, 7, 9, 8, 8, 11, 9, 6, 7, 10, 9, 7,
> 9, 7, 8, 9, 8, 7, 9]
>
>
> Is there a better way than using, e.g.
>
> >>> shape(where(array(data)==10))[1]
> 2
>
>
> to compute the occurrence of 10 in the list which is 2 in this case ?
>
> Nils
>
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion at scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20070807/a6dd9f44/attachment.html>


More information about the NumPy-Discussion mailing list