Why do torch.add and torch.einsum return different results?

Viewed 53
t=m+n
x=torch.einsum('xyzw,xyzw->xyzw',m,n)

When I try this code, I get x that's different from t, which is surprising. Why does this happen?

1 Answers

einsum is actually a product of its inputs. It's only a sum over the indexes that do not occur in the output.

So,

x=torch.einsum('xyzw,xyzw->xyzw',m,n)

is actually equivalent to

x = m * n
Related