Identifying rows and columns of a matrix that satisfy a specific feature
One possibility is:
z = Position[mat, {0 ..}];
c = Position[Transpose@mat, {0 ..}];
Delete[Transpose@Delete[mat // Transpose, c], z]
An alternative is:
Select[Transpose[Select[mat, Not[And @@ PossibleZeroQ[#]] &]],
Not[And @@ PossibleZeroQ[#]] &] // Transpose
nonzerorows = Flatten @ Position[mat, Except @ {0 ..}, 1, Heads -> False]
{1, 2, 3, 5, 6, 7, 9, 10, 11, 13, 14, 15}
nonzerocols = Flatten @ Position[Transpose @ mat, Except @ {0 ..}, 1, Heads -> False]
{1, 2, 3, 5, 6, 7, 9, 10, 11, 13, 14, 15}
mat1 = mat[[nonzerorows, nonzerocols]];
mat1 // MatrixForm
{zerorows, zerocols} = MapThread[Complement[Range @ # @ Dimensions[mat], #2] &,
{{First, Last}, {nonzerorows, nonzerocols}}]
{{4, 8, 12, 16}, {4, 8, 12, 16}}
mat2 = DeleteCases[{}] @ ReplacePart[mat,
{Alternatives @@ zerorows, _} | {_, Alternatives @@ zerocols} -> Nothing];
mat2 == mat1
True
You can get the final matrix directly using
mat3 = Nest[DeleteCases[{0 ..}] @* Transpose, mat, 2]
mat3 == mat1
True
A row of all zeros also sums to zero... so you can apply Total to sum the elements of each row and then select the positions that are zero:
Position[Total[mat], _?((# == 0) &)]
{{4}, {8}, {12}, {16}}
If you just want the row numbers, you can Flatten. For columns, do the same thing to the transpose of mat. If your matrix has both positive and negative entries, apply Abs to mat.