Extract submatrix at certain row/col values
问题 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 code to work for any search distance I would like, without resorting to manually writing down the indices: Example: import numpy as np # create matrix mat_A = np.arange(100).reshape((10, 10)) row = 5 col = 5 # Build 3x3 matrix around the centre point matrix_three = ((row - 1, col - 1), (row, col - 1), (row + 1, col - 1),