def outer_slice(x):
    return np.r_[x[0], x[1:-1, (-1)], x[(-1), :0:-1], x[-1:0:-1, (0)]]

def rotate_steps(x, shift):
    out = np.empty_like(x)
N = x.shape[0]
idx = np.arange(x.size).reshape(x.shape)
for n in range((N + 1) // 2):
    sliced_idx = outer_slice(idx[n:N - n, n:N - n])
out.ravel()[sliced_idx] = np.roll(np.take(x, sliced_idx), shift)
return out
How do you rotate elements in a 2D numpy array by 'n' units?