Extract submatrix at certain row/col values

后端 未结 2 1338
慢半拍i
慢半拍i 2021-01-21 05:45

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

2条回答
  •  逝去的感伤
    2021-01-21 06:19

    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]]
    

提交回复
热议问题