I’m writing something like:

`a=Variable(torch.randn(1).type(torch.FloatTensor),requires_grad=True) b=Variable(torch.randn(3,3))`

how to compute the product

THX!

What kind of product do you need? You want to scale each matrix element by the same scalar? Try this:

```
a = ...
b = ...
b * a.expand_as(b)
```

1 Like

I am wondering if using expand_as is efficient in this case ? does it store only the original value and the repetitions across each axis or something similar ? it would be cheaper to divide each matrix element by the same value without having to create the whole matrix containing the same values.