I want a tensor (in the multi-linear algebra sense) which takes as an input a matrix $A$ of size $n \times n$ and returns as output an $n \times n$ matrix which is diagonal (zero off-diagonal), and on each diagonal element $(i,i)$, the value is $\sum_{j} A_{ij}$.
Is there such a tensor (I am guessing it would be of dimensions $n \times n \times n \times n$)?
Thanks.
By hypothesis, we have
$$T_{ab}^{\,ij}A_{ij}=\delta_{ab}\sum_j A_{aj}=\delta_{ab}1^jA_{aj}=\delta_{ab}1^j\delta_{a}^iA_{ij},$$
where $1^j$ has component $1$ for each index $j$. So $T_{ab}^{\,ij}=\delta_{ab}^i1^j$ is the desired tensor.