Interleave Zeros

easynumpy_manipulation

Implement interleave_zeros(z, nz).

Given a 1D array z and a count nz, return a new 1D array with nz zeros inserted between each pair of consecutive elements of z. The result has length len(z) + (len(z) - 1) * nz. Example: z = [1, 2, 3], nz = 2[1, 0, 0, 2, 0, 0, 3]. No for/while loops.

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

Your solution

Edit interleave_zeros 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

Allocate the spaced-out array of zeros, then assign z into every (nz+1)-th slot: out[::nz+1] = z.