Extract the symmetric matrix built-in another matrix

Maybe a bit simpler:

M Transpose[M]

Comparing with Henrik's answer:

M Subtract[1, Unitize[Subtract[Transpose[M], M]]] == M Transpose[M]
True

Maybe this is what you are looking for. I interpreted your question as if you want to replace all nonsymmetric entries of the input matrix by zeroes and as if the input matrix is not necessarily binary.

A = M Subtract[1, Unitize[Subtract[Transpose[M], M]]];

A = Floor @ Symmetrize @ M;

TeXForm @ MatrixForm @ A

$\left( \begin{array}{cccccc} 0 & 1 & 1 & 0 & 1 & 0 \\ 1 & 0 & 0 & 1 & 0 & 1 \\ 1 & 0 & 0 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 & 0 & 0 \\ 1 & 0 & 0 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 & 0 & 0 \\ \end{array} \right)$

Note: This is much slower than the methods in the answers by bill s and Henrik Schumacher.

Tags:

Matrix