画像 (または任意の ND 配列) の中心ピクセルを取得するための numpy のインデックス作成の省略形はありますか?
例:
cutout = xc[xc.shape[0]/2-30:xc.shape[0]/2+30,xc.shape[1]/2-30:xc.shape[1]/2+30]
関数を定義できます
def get_center_pixels(arr, npix):
slices = [slice(shape/2-npix,shape/2+npix) for shape in arr.shape]
return arr[slices]
cutout = get_center_pixels(xc,30)
これを行うためのより良い方法または組み込みの方法はありますか?