# Revision history [back]

### Given a matrix $M$ how to form the following matrix $N$ from $M$.

Given a matrix $M$ how to form the following matrix $N$ from $M$.

Suppose $M=$\begin{bmatrix} 0 &3 \ 2 &0 \end{bmatrix}

Here $M$ is a $2\times 2$ matrix with 1st row $[0,3]$ and 2nd row $[2,0]$.

We need to form $N$ such that

$N=$ \begin{bmatrix} 3& 3\ 2&2\end{bmatrix}

Here $N$ is a $2\times 2$ matrix with 1st row $[3,3]$ and 2nd row $[2,2]$.

Thus $N$ is formed from $M$ by just adding all the off the diagonal elements of $M$ in a given row to the diagonal element

So the diagonal element of $N$ is the sum of all the remaining entries in a given row of $M$ whereas the rest of the elements of $N$ are the same as $M$.

So the elements of $N$ are obtained from $M$ in the following way :

$a_{11}=0+3=3, a_{12}=3,a_{21}=2,a_{22}=2+0=2$

How to code it?