Zero Border Around a Matrix

easynumpy_manipulation

Implement pad_border(X).

Given a 2D array X of shape (m, n), return a (m + 2, n + 2) array that is X surrounded by a one-cell border of zeros. Build it yourself with slicing — np.pad is not allowed — and no for/while loops.

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

Your solution

Edit pad_border 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 zeros array two larger in each dimension, then drop X into the middle with slicing.