def neighbors(arr, x, y, n=3):
    """ Given a 2D-array, returns an nxn array whose "center" element is arr[x,y]"""
arr = np.roll(np.roll(arr, shift=-x + 1, axis=0), shift=-y + 1, axis=1)
return arr[:n, :n]
print(A)
print(neighbors(A, 0, 0))
print(neighbors(A, 1, 0))
How do I select a window from a numpy array with periodic boundary conditions?