maple maple - 1 year ago 280
Python Question

How to get count of all element in numpy?

suppose I have an array in numpy


What I want is to get two arrays to give count of each element:


How can I do this without any for loops?

Answer Source
In [1043]: np.unique(np.array([1,1,2,3,4,5,5,5,6,7,7,7,7]),return_counts=True)
Out[1043]: (array([1, 2, 3, 4, 5, 6, 7]), array([2, 1, 1, 1, 3, 1, 4]))
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download