How to form submatrices with some inconsistent rows and matrix columns

I have a 10 by 10 matrix. I want to create a submatrix from this main matrix using all the rows and columns except the 1st, 2nd and 8th columns and rows.
I know that Part can be used to form a submatrix, but the examples mainly concern the formation of a submatrix using only consecutive rows and columns.

+5
source share
2 answers

If this is your matrix:

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

This will do the trick for the case in question:

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

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

+7
source

Here is another way.

Call your matrix

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

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

subTest == test[[#, #]] &[Complement[Range[10], {1, 2, 8}]]
(* True *)
+6

All Articles