Originally, I have a matrix of dimension (1040, 1040). This a very large matrix to visually inspect some features. I mimic the matrix of concern as:
mat={
{1, 2, 3, 0, 5, 6, 7, 0, 9, 10, 11, 0, 13, 14, 15, 0},
{17, 18, 19, 0, 21, 22, 23, 0, 25, 26, 27, 0, 29, 30, 31, 0},
{33, 34, 35, 0, 37,38, 39, 0, 41, 42, 43, 0, 45, 46, 47, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{65, 66, 67, 0, 69, 70, 71, 0, 73, 74, 75, 0, 77, 78, 79, 0},
{81, 82, 83, 0, 85, 86, 87, 0, 89, 90, 91, 0, 93, 94, 95, 0},
{97,98,99,0,101,102, 103, 0, 105, 106, 107, 0,109, 110, 111, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{129,130,131,0,133,134,135,0,137,138,139,0,141,142,143, 0},
{145,146,147,0,149,150,151,0,153,154,155,0,157, 158, 159, 0},
{161,162,163,0,165,166,167,0,169,170, 171, 0, 173, 174, 175, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{193, 194, 195, 0,197,198, 199, 0,201,202,203,0,205,206,207, 0},
{209,210,211,0,213, 214, 215, 0, 217, 218,219,0,221,222,223, 0},
{225, 226, 227, 0, 229, 230, 231,0,233,234,235,0,237,238,239,0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
}
As seen, matrix mat
has some rows and columns with all zero entries.
- I like to identify those rows and columns with all zero entries. For example, using
mat
, I like to have a list of row indices showing the row index numbers associated with zero-entry rows: {4, 8, 12, 16}. Likewise, for the column index, {4, 8, 12, 16}. - Then, after constructing the row/column index lists, I like to remove those zero rows/columns from the original matrix
mat
.
Using Drop[mat,{.,.},{.,.}]
, I can accomplish the above goal for the given matrix mat
as zero rows and columns are placed systematically. But my problem is that I cannot see the actual mat
visually and the zero rows/columns are unsystematically placed.
Thanks for your help.
Transpose[Transpose[mat] /. {0 ..} -> Nothing[]] /. {0 ..} -> Nothing[]
$\endgroup$