Calculate Mode

Find the most frequent value(s) in an array.

Code

General
from collections import Counter
freq = Counter(arr)
max_freq = max(freq.values())
return [n for n, f in freq.items() if f == max_freq]

Parameters

Array of numbers

Server

More Python Snippets