Is there a function or more concise notation to get b or bb in the code snippet below?
import numpy as np
a = np.arange(12).reshape(3, 4)
c = (1, 2)
r = 1
b = a[c[0]-r:c[0]+r, c[1]-r:c[1]+r]
bb = a[c[0]-r:c[0]+r+1, c[1]-r:c[1]+r+1]
The objective is to get a subarray defined by a center index c and radius r (L1-norm).
bb?. It seems like a pythonic solution and how numpy is intended to work.c-r:c+r.a[tuple(slice(i-r, i+r) for i in c)]for higher dimensions.