In numpy
/ scipy
, is there an efficient way to get frequency counts for unique values in an array?
Something along these lines:
x = array( [1,1,1,2,2,2,5,25,1,1] )
y = freq_count( x )
print y
>> [[1, 5], [2,3], [5,1], [25,1]]
( For you, R users out there, I'm basically looking for the table()
function )
from collections import Counter Counter(x)
I was also interested in this, so I did a little performance comparison (using perfplot, a pet project of mine). Result:
is by far the fastest. (Note the log-scaling.)
Code to generate the plot: