Unless I'm understanding the question incorrectly here (but the np.pad solution is doing what I first expected), the fancy indexing solution does not work.
The first solution extends the array (final shape is (5,5)) while the second solution does not. Maybe it's worth to add a comment saying external/internal border to distinguish between the two solutions.
An example:
Unless I'm understanding the question incorrectly here (but the
np.pad
solution is doing what I first expected), the fancy indexing solution does not work.