Given: square matrix, and list which represents the index of rows to be removed, and it also represent at the same time the index of the columns to be removed (it is square matrix, so only one list is needed).
output: the square matrix, with BOTH the rows and the columns columns in the list removed.
Assume valid list of indices.
This is an example
So the above says to remove the second and the 4th rows, and also the second and the 4th column.
I could not figure how to use Delete[]
to remove both rows and columns at the same time, and I really did not want to make a list of each individual element index I want to remove.
But I could use Delete
to remove rows.
This below how I solved it, I removed the rows first, then transposed the matrix, and then removed the rows of the new matrix (which will be the columns of the original), then transposed the result back to obtain what I wanted.
like this:
a = {{0, 5, 2, 3, 1, 0}, {4, 3, 2, 5, 1, 3}, {4, 1, 3, 5, 3, 2}, {4,
4, 1, 1, 1, 5}, {3, 4, 4, 5, 3, 3}, {5, 1, 4, 5, 2, 0}};
del = {{2}, {4}};
a = Delete[a, del];
a = Delete[Transpose[a], del];
(a = Transpose[a]) // MatrixForm
my question: Is there a shorter way using Delete (or another one of those expert tricks) to do this in a better way ?
thanks