hhh
hhh

Reputation: 117

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

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?

Upvotes: 1

Views: 172

Answers (1)

MWB
MWB

Reputation: 12597

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

Upvotes: 2

Related Questions