Repeat Each Element

easynumpy_combine

Implement repeat_each(x, k).

Given a 1D array x and an integer k, return a 1D array in which each element of x is repeated k times consecutively. For example repeat_each([1, 2, 3], 2)[1, 1, 2, 2, 3, 3] (not [1, 2, 3, 1, 2, 3]). No for/while loops.

Constraints
  • no for/while loops

Your solution

Edit repeat_each 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.repeat(x, k) repeats each element k times; contrast with np.tile, which repeats the whole array.