@jit  
def pmap2(f, x, width = (3,3)):
  width_x, width_y = width 
  n_rows, n_cols = x.shape
  hx = width_x / 2
  hy = width_y / 2
  
  def local_apply((i,j)):
    lx = __builtins__.max(i-hx, 0)
    ux = __builtins__.min(i+hx+1, n_rows)
    ly = __builtins__.max(j-hy, 0)
    uy = __builtins__.min(j+hy+1, n_cols)
    return f(x[lx:ux, ly:uy])
    
  return imap(local_apply, x.shape)
Patch-map where the function can accept both interior windows
dataset/ETHPy150Open iskandr/parakeet/parakeet/lib/patchmap.py/pmap2