image = np.array([[1, 1, 1, 0, 0], [0, 1, 1, 1, 0], [0, 0, 1, 1, 1], [0, 0,
    1, 1, 0], [0, 1, 1, 0, 0]])
m = np.array([[1, 0, 1], [0, 1, 0], [1, 0, 1]])
How to perform iterative 2D operation on 4D numpy array