[Numpy-discussion] Find index of repeated numbers in array
Robert Cimrman
cimrman3@ntc.zcu...
Wed Dec 10 10:43:44 CST 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