Inverse of bincount
mediumnumpy_manipulationImplement repeat_counts(counts).
Given a 1D non-negative integer array counts, return a 1D array in which
index i appears counts[i] times, in order. For example
counts = [2, 0, 3] → [0, 0, 2, 2, 2]. (This is the inverse of
np.bincount.) No for/while loops.
Constraints
- no scipy, sklearn
- no for/while loops
Your solution
Edit repeat_counts and run the real pytest suite in your browser — no install required. Your code is saved locally.
Loading the Python runtime (first run only)…
Hints
Hint 1
np.repeat(np.arange(len(counts)), counts) repeats each index by its count.