Hi all,
Is there any mechanism in Torch similar to broadcasting in numpy?
The problem is that I have a NxD matrix X and a vector y of length N. I would like to add each element in y to corresponding row of X. If it were numpy, then the code would be:
X + y[:, numpy.newaxis]
Is there an elegant way to do it in torch?
Thanks.
@yangky11
X = torch.randn(3,4)
y = torch.randn(3)
z = X + y:view(3,1):expandAs(X)
Most helpful comment
@yangky11