Torch7: no broadcasting in torch?

Created on 17 Sep 2015  路  1Comment  路  Source: torch/torch7

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.

Most helpful comment

@yangky11

X = torch.randn(3,4)
y = torch.randn(3)
z = X + y:view(3,1):expandAs(X)

>All comments

@yangky11

X = torch.randn(3,4)
y = torch.randn(3)
z = X + y:view(3,1):expandAs(X)
Was this page helpful?
0 / 5 - 0 ratings

Related issues

stonebig picture stonebig  路  7Comments

visonpon picture visonpon  路  3Comments

mf27 picture mf27  路  5Comments

n3011 picture n3011  路  9Comments

galv picture galv  路  4Comments