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?

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

2 Answers 2


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


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}$.

  • $\begingroup$ That's exactly what I was looking for. Very elegant, thank you! $\endgroup$
    – MM8
    Commented Feb 12, 2016 at 15:13
  • $\begingroup$ Is it possible to write that new tensor you introduce as a combination of Kronecker deltas without messing with the summation convention? $\endgroup$
    – MaxD
    Commented Oct 6, 2021 at 11:41
  • $\begingroup$ @MaxD If you're not using the summation convention then $\delta^\alpha_{\;\beta\gamma}=\delta^\alpha_{\;\beta}\delta^\alpha_{\;\gamma}$. $\endgroup$ Commented Oct 6, 2021 at 13:54
  • $\begingroup$ @OscarCunningham That's what I wanted to exclude by saying "without", probably could've been more clear. $\endgroup$
    – MaxD
    Commented Oct 6, 2021 at 15:33
  • 1
    $\begingroup$ @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. $\endgroup$ Commented 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.

Now I'm not as ashamed of ChatGPT for being confused about this subject.

  • $\begingroup$ "Now I'm not as ashamed of ChatGPT" , but you should be it. $\endgroup$
    – Peter
    Commented Jul 24, 2023 at 12:21
  • $\begingroup$ @Peter The point is that humans are struggling with this question. Why would we expect a robot to be able to answer it? Also, I never said I was unashamed of ChatGPT, only less ashamed. $\endgroup$ Commented Jul 25, 2023 at 11:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .