Matrix form for the sum of squares of the off-diagonal elements of a matrix I wonder if there exists a matrix ("condensed") formula for 
$$\sum\limits_{i\ne j}a_{ij}^2$$ 
where $A=[a_{ij}]$ is a $n \times n$ matrix.
To be more precise, for example, it is known that 
$$\sum\limits_{i,j}a_{ij}^2 = \mbox{tr} \left( A^T A \right)$$
or that 
$$\sum\limits_{i\ne j} a_{ij} = \mbox{tr}(JA)$$
where $J$ is a "constant" matrix having $0$'s on the diagonal and $1$'s elsewhere. I would be interested in a similar formula for $$\sum\limits_{i\ne j}a_{ij}^2$$ involving trace, the matrix $A$ and eventually some other "constant" matrix/matrices.
 A: We have
$$\sum_{i\neq j} a_{ij}^2 = \sum_{i,j} a_{ij}^2 - \sum_{i}a_{ii}^2 = tr(A^T A) - \sum_{i}a_{ii}^2,$$
so it suffices to find an expression for $\sum_{i}a_{ii}^2$. Let $E_{ij}$ denote the matrix with a 1 at entry $(i,j)$ and zeros everywhere else. Then $E_{ii}A$ has zeros in every row except the ith (where the row is the same as the ith row of $A$). Hence, the only nonzero term on the diagonal of $(E_{ii}A)^2$ is the entry $a_{ii}^2$. This gives $a_{ii}^2 = tr((E_{ii}A)^2)$. Therefore,
$$\sum_{i\neq j} a_{ij}^2 = tr(A^T A) + \sum_{i} tr((E_{ii}A)^2).$$
A: The Hadamard ($\odot$) product and Frobenius $(:)$ product 
$$\eqalign{
A &= B\odot C &\implies A_{ij} = B_{ij}C_{ij} \\
\alpha &= B:C &\implies \alpha = \sum A_{ij} = \sum B_{ij}C_{ij} \\
}$$ can be used to write concise expressions for the sum of the off-diagonal elements $\big(J:A\big)$, the sum of squares of all the elements $\big(A:A\big)$, and the sum of squares of the off-diagonals $\big(J:(A\odot A)\big)$.
Or the Frobenius product can be replaced with the trace function, since
$$B:C \equiv {\rm Tr}(B^TC)$$
