Adding tensors of different sizes

torch can add tensors of different sizes. But it is not clear what is the rule when two tensors of different sizes are added.

import torch
import numpy
x = torch.from_numpy(numpy.array([[1,2,3], [4, 5, 6]]))
y = torch.from_numpy(numpy.array([1,2,3]))
print x
print y
print torch.add(x, y)

It looks like it tries to broadcast the tensors so they’re the same size and then adds them together. I agree the documentation is a little unclear about this.

1 Like