[Numpy-discussion] Multiplicity of an entry

Christopher Barker Chris.Barker@noaa....
Mon Oct 26 13:12:49 CDT 2009


Alan G Isaac wrote:
> On 10/26/2009 4:04 AM, Nils Wagner wrote:
>> how can I obtain the multiplicity of an entry in a list
>> a = ['abc','def','abc','ghij']
> 
> That's a Python question, not a NumPy question.

but we can make it a numpy question!

In [15]: a = np.array(['abc','def','abc','ghij'])


In [16]: a
Out[16]:
array(['abc', 'def', 'abc', 'ghij'],
       dtype='|S4')

In [17]: for item in set(a):
     print item, (a == item).sum()

abc 2
ghij 1
def 1

I'll leave pro=filing to the OP.

-Chris



-- 
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker@noaa.gov


More information about the NumPy-Discussion mailing list