Interleave Zeros Between Elements

easynumpy_manipulation

Implement add_zeros(x).

Given a 1D integer array x, return a new array with a single zero inserted between each pair of adjacent elements: [1, 2, 3][1, 0, 2, 0, 3]. An array with fewer than two elements is returned unchanged. No for/while loops — use a strided assignment.

Constraints
  • no for/while loops

Your solution

Edit add_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 a zero array of length 2*len(x)-1, then write x into every other slot with a strided assignment out[::2] = x.