is there a tensor that does the following? 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.
 A: Let $k$ be our ground field, and let $\mathrm{M}_n\left(k\right)$ denote the algebra of $n\times n$ matrices over $k$.
Let $u:\mathrm{M}_n\left(k\right)\to \mathrm{M}_n\left(k\right)$ be the map you described, i. e., the map which takes any matrix $A\in \mathrm{M}_n\left(k\right)$ to the matrix
$\mathrm{diag}\left(\sum\limits_j A_{1,j}, \sum\limits_j A_{2,j}, ..., \sum\limits_j A_{n,j}\right) \in \mathrm{M}_n\left(k\right)$.
This map $u$ is $k$-linear, i. e., an element of $\mathrm{Hom}\left(\mathrm{M}_n\left(k\right),\mathrm{M}_n\left(k\right)\right)\cong \left(\mathrm{M}_n\left(k\right)\right) \otimes \left(\mathrm{M}_n\left(k\right)\right)^{\ast}$. Since $\mathrm{M}_n\left(k\right)\cong k^n \otimes k^{n\ast}$, this map thus can be viewed as an element of $\left(k^n \otimes k^{n\ast}\right) \otimes \left(k^n \otimes k^{n\ast}\right) ^{\ast} \cong k^n \otimes k^{n\ast} \otimes k^{n\ast} \otimes k^n$. So yes, it is a tensor.
What tensor? I wish I could answer this in a nice and simple basis-free way, but I don't think there is such a way (note that even the trace tensor, which lies in $k^n \otimes k^{n\ast}$, is not easily described without a basis - which is not surprising given that it only exists in the finite-dimensional setup). Here is how to do it with a basis: For any $i$ and $j$, let $E_{i,j}$ be the $n\times n$ matrix over $k$ whose $\left(i,j\right)$-th entry is $1$ and whose all other entries are $0$. Then, $\left(E_{i,j}\right)_{1\leq i\leq n,\ 1\leq j\leq n}$ is a basis of the $k$-vector space $\mathrm{M}_n\left(k\right)$. Let $\left(E_{i,j}^{\ast}\right)_{1\leq i\leq n,\ 1\leq j\leq n}$ be its dual basis of the $k$-vector space $\mathrm{M}_n\left(k\right)^{\ast}$. Then,
$u\left(A\right) = \mathrm{diag}\left(\sum\limits_j A_{1,j}, \sum\limits_j A_{2,j}, ..., \sum\limits_j A_{n,j}\right) = \sum\limits_i\sum\limits_j \underbrace{A_{i,j}}_{=E_{i,j}^{\ast}\left(A\right)} E_{i,i} =  \sum\limits_i\sum\limits_j E_{i,j}^{\ast}\left(A\right) E_{i,i}$
for any matrix $A$. Thus, the map $u$ corresponds to the element $\sum\limits_i\sum\limits_j  E_{i,i} \otimes E_{i,j}^{\ast}$ of $\left(\mathrm{M}_n\left(k\right)\right) \otimes \left(\mathrm{M}_n\left(k\right)\right)^{\ast}$.
Now let $\left(e_1,e_2,...,e_n\right)$ be the standard basis of $k^n$, and $\left(e_1^{\ast},e_2^{\ast},...,e_n^{\ast}\right)$ be its dual basis of $k^{n\ast}$. Since the identification of $\mathrm{M}_n\left(k\right)$ with $k^n \otimes k^{n\ast}$ equates $E_{p,q}$ with $e_p \otimes e_q^{\ast}$ for all $p$ and $q$, the element $\sum\limits_i\sum\limits_j  E_{i,i} \otimes E_{i,j}^{\ast}$ of $\left(\mathrm{M}_n\left(k\right)\right) \otimes \left(\mathrm{M}_n\left(k\right)\right)^{\ast}$ can be seen as the element $\sum\limits_i\sum\limits_j e_i \otimes e_i^{\ast} \otimes e_i^{\ast} \otimes e_j$ of $k^n \otimes k^{n\ast} \otimes k^{n\ast} \otimes k^n$. So this is the tensor representing $u$.
A: 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.
