我有一个400列,1000行的矩阵
从第10行第30列开始到第390行第960列到第390行从中提取子矩阵的最佳方法是什么?
嗡嗡声
答案 0 :(得分:1)
如果您的矩阵称为arr
,请使用:
arr[10:391,30:961]
请记住python的索引为零!
例如,在具有10行5列的矩阵上:
>>> arr
array([[0.41296756, 0.14399754, 0.12606098, 0.61114244, 0.83243229],
[0.91409281, 0.28715535, 0.63134933, 0.49837152, 0.15927328],
[0.89021618, 0.16226017, 0.75576869, 0.4949617 , 0.86590637],
[0.7684741 , 0.82399817, 0.48887077, 0.12121645, 0.64524496],
[0.37356536, 0.4548252 , 0.09608423, 0.49361169, 0.12475545],
[0.74875009, 0.16289433, 0.84103655, 0.09670591, 0.34296308],
[0.0697272 , 0.87959546, 0.2928768 , 0.53756533, 0.96180757],
[0.3495039 , 0.09705972, 0.05581994, 0.95367967, 0.94351724],
[0.03739738, 0.65043277, 0.94139692, 0.82945502, 0.51765616],
[0.07702866, 0.57164611, 0.55674663, 0.21082212, 0.76406612]])
我可以使用以下方法选择5-7行,1-3列:
>>> arr[5:8,1:4]
array([[0.16289433, 0.84103655, 0.09670591],
[0.87959546, 0.2928768 , 0.53756533],
[0.09705972, 0.05581994, 0.95367967]])