Torch Tensor of different dimensions can not be added, such as 2x3x2+1x3x2, but numpy allowed to do this?


(Zp S) #1

such as:

b = torch.rand(1,3,2)
x = a+b```
if use numpy:
```a = torch.rand(2,3,2).numpy()
b = torch.rand(1,3,2).numpy()
x = a+b```
numpy will get correct result. but pytorch will show `RuntimeError: inconsistent tensor size at /Users/soumith/code/builder/wheel/pytorch-src/torch/lib/TH/generic/THTensorMath.c:831`

sorry I am new in pytorch.
Thanks

(Thomas V) #2

The master branch has broadcasting.

Best regards

Thomas