Is there a "freq" function in numpy/python?
numpy, python
Solution
Yes, Python's collections.Counter has direct support for finding the most frequent elements:
>>> from collections import Counter
>>> Counter('abracadbra').most_common(2)
[('a', 4), ('r', 2)]
>>> Counter([1,2,1,3,3,4]).most_common(2)
[(1, 2), (3, 2)]
With numpy, you might want to start with the histogram() function or the bincount() function.
With scipy, you can search for the modal element with mstats.mode.
Problem
Suppose you have: ``` arr = np.array([1,2,1,3,3,4]) ``` Is there a built in function that returns the most frequent element?