Most Frequent Value

easynumpy_reductions

Implement most_frequent(x).

Given a 1D array x of non-negative integers, return the value that occurs most often. If several values tie, return the smallest of them. No for/while loops.

Constraints
  • no scipy, sklearn
  • no for/while loops

Your solution

Edit most_frequent and run the real pytest suite in your browser — no install required. Your code is saved locally.

⌘/Ctrl + ↵

Loading the Python runtime (first run only)…

Hints

Hint 1

np.bincount counts occurrences of each value; argmax gives the most frequent.