how to multiply three arrays with different dimension in PyTorch
enter image description here
L array dimension is (d,a) ,B is (a,a,N) and R is (a,d). By multiplying these arrays I have to get an array size of (d,d,N). How could I implement this is PyTorch

A possible and straightforward approach is to apply torch.einsum (read more here):
&gt;&gt;&gt; torch.einsum('ij,jkn,kl-&gt;iln', L, B, R)


Where j and k are the reduced dimensions of L and R respectively. And n is the &quot;batch&quot; dimension of B.

The first matrix multiplication will reduce L@B (let this intermediate result be o):
ij,jkn-&gt;ikn


The second matrix multiplication will reduce o@R:
ikn,kl-&gt;iln



Which overall sums up to the following form:
ij,jkn,kl-&gt;iln

