I need to slice a 2D input array from row/col indices and a slicing distance. In my example below, I can extract a 3x3 submatrix from an input matrix, but I cannot adapt this co
Numpy has matrix slicing, so you can slice on both rows and columns.
mat_A[4:7, 4:7]
returns
[[44, 45, 46],
[54, 55, 56],
[64, 65, 66]]
S=3 # window "radius"; S=3 gives a 5x5 submatrix
mat_A[row-S+1:row+S,col-S+1:col+S]
#array([[33, 34, 35, 36, 37],
# [43, 44, 45, 46, 47],
# [53, 54, 55, 56, 57],
# [63, 64, 65, 66, 67],
# [73, 74, 75, 76, 77]])