# Is it possible to write the Hadamard product of two matrices in tensor notation?

Say I have two $4 \times 4$ matrices $(A^{\alpha \beta})$ and $(B^{\mu\nu})$ and want to compute the Hadamard (entry-wise) product. Is there an elegant way of writing this down in the common component, i.e. tensor, notation? Would it be something like $A^{\alpha \beta} B^{\alpha \beta}$ or is that not sufficient? Would this lead to conflicts with Einsteins summation convention?

• $(A,B) \to \sum_{ij} (e_i^T A e_j) (e_i^T B e_j) e_i e_j^T$ Feb 12, 2016 at 11:18

If you aren't using the summation convention then $C^{\alpha\beta}=A^{\alpha\beta}B^{\alpha\beta}$ is fine.

If you are using the summation convention then $A^{\alpha\beta}B^{\alpha\beta}$ means

$$\sum_{\alpha\beta}A^{\alpha\beta}B^{\alpha\beta}$$

which is a scalar rather than a matrix. In this case the thing to do is to define a new tensor $\delta^\alpha_{\;\beta\gamma}$ such that

$$\delta^\alpha_{\;\beta\gamma}=\begin{cases} 1&\text{if}\;\alpha=\beta=\gamma\\ 0&\text{otherwise}\\ \end{cases}$$

in your basis. Then define $C^{\alpha\beta}=\delta^\alpha_{\;\gamma\delta}\delta^\beta_{\;\eta\phi}A^{\gamma\eta}B^{\delta\phi}$.

• That's exactly what I was looking for. Very elegant, thank you!
– MM8
Feb 12, 2016 at 15:13
• Is it possible to write that new tensor you introduce as a combination of Kronecker deltas without messing with the summation convention?
– MaxD
Oct 6, 2021 at 11:41
• @MaxD If you're not using the summation convention then $\delta^\alpha_{\;\beta\gamma}=\delta^\alpha_{\;\beta}\delta^\alpha_{\;\gamma}$. Oct 6, 2021 at 13:54
• @OscarCunningham That's what I wanted to exclude by saying "without", probably could've been more clear.
– MaxD
Oct 6, 2021 at 15:33
• @MaxD If you're using the summation convention then using a combination of $\delta$s and contractions will always yield an even number of indices. Another point is that $\delta^\alpha_{\;\beta}$ is basis invariant whereas $\delta^\alpha_{\;\gamma\delta}$ is not. Oct 6, 2021 at 15:47

As long as you include both sides of the equation, Einstein notation works well here:

• Variables occurring on only one side of the equation are summed.
• Variables occurring on both sides of the equation are not.

With this convention, $$C^{\alpha\beta}=A^{\alpha\beta}B^{\alpha\beta}$$ is perfectly clear.

This is the convention used by Numpy, PyTorch, and, I assume, Tensorflow. You can compute an elementwise multiplication with np.einsum('ij,ij->ij', A, B) or torch.einsum('ij,ij->ij', A, B). Since Tensorflow's einsum has a similar notation, I assume it would also work there.

Therefore, contrary to Oscar's answer, an elementwise multiplication can be represented even when summing convention (that is, Einstein notation) is assumed. There is no need to introduce delta notation here.