[Numpy-discussion] Find index of repeated numbers in array
Robert Cimrman
cimrman3 at ntc.zcu.cz
Wed Dec 10 11:43:44 EST 2008
Ross Williamson wrote:
> Hi Everyone
>
> I think I'm missing something really obvious but what I would like to
> do is extract the indexes from an array where a number matches - For
> example
>
> data = [0,1,2,960,5,6,960,7]
>
> I would like to know, for example the indices which match 960 - i.e.
> it would return 3 and 6
import numpy as np
In[14]: np.where( np.array( data ) == 960 )
Out[14]: (array([3, 6]),)
If you need to count all of the items, try something like
np.histogram( data, np.max( data ) )
cheers,
r.
More information about the NumPy-Discussion
mailing list