How to form submatrices with some non-consecutive rows and columns of a matrix

邮差的信 提交于 2019-12-05 11:25:43

If this is your matrix:

tst = RandomInteger[10, {10, 10}];

This will do the trick for the case at hand:

tst[[{3, 4, 5, 6, 7, 9, 10}, {3, 4, 5, 6, 7, 9, 10}]]

Instead of explicit list, you could use Complement[Range[10],{1,2,8}].

Here's another way.

Call your matrix

test = Array[m, {10, 10}]

Then your sub matrix is

subTest = Nest[Delete[Transpose[#], {{1}, {2}, {8}}] &, test, 2]

Compare with Leonid's method

subTest == test[[#, #]] &[Complement[Range[10], {1, 2, 8}]]
(* True *)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!