Hi Pedro!



 pedro-mgb:

I want to multiply these two tensors along the dimension they have in common (a), and such that their output will be a 4 d tensor (e.g. dimensions b x c x d x e).


torch.einsum 1 is the general-purpose tool for “contracting” various
indices of tensors.  Here is an example:
>>> import torch
>>> torch.__version__
'1.7.1'
>>> a = 3
>>> b = 2
>>> c = 5
>>> d = 3
>>> e = 4
>>> t1 = torch.randn ((a, b, c))
>>> t2 = torch.randn ((a, d, e))
>>> tt = torch.einsum ('ijk,ilm -> jklm', t1, t2)
>>> tt.shape
torch.Size([2, 5, 3, 4])

Best.
K. Frank