title: How does torch.einsum perform this 4D tensor multiplication?
body: <p>I have come across a code which uses <code>torch.einsum</code> to compute a tensor multiplication. <a href="https://rockt.github.io/2018/04/30/einsum" rel="nofollow noreferrer">I am able to understand the workings for lower order tensors</a>, but, not for the 4D tensor as below:</p>
  <pre class="lang-py prettyprint-override"><code>import torch
  
  a = torch.rand((3, 5, 2, 10))
  b = torch.rand((3, 4, 2, 10))
  
  c = torch.einsum('nxhd,nyhd-&gt;nhxy', [a,b])
  
  print(c.size())
  
  # output: torch.Size([3, 2, 5, 4])
  </code></pre>
  <p>I need help regarding:</p>
  <ol>
  <li>What is the operation that has been performed here (explanation for how the matrices were multiplied/transposed etc.)?</li>
  <li>Is <code>torch.einsum</code> actually beneficial in this scenario?</li>
  </ol>