Premium problem80. Centered Subpart with Fill

Hard Locked

Extract a subpart of array Z with the given shape, centered on the element at position, padding with fill where it falls outside Z. Return the subpart.

Input

Z =
[[ 0  1  2  3  4]
 [ 5  6  7  8  9]
 [10 11 12 13 14]
 [15 16 17 18 19]
 [20 21 22 23 24]]
shape = (3, 3)
position = (1, 1)
fill = 0

Output

[[ 0  1  2]
 [ 5  6  7]
 [10 11 12]]

Premium problem

This one's part of Premium. Unlock the full NumPy track plus every other premium problem on the site.

Implement solve(...)