Multiply torch tensor along a dimension

lets say I have a tensor t with the dimensions (b, m, n) and I have a vector v of size (b). I want to multiply these together and have each (m, n) entry of t multiplied by the corresponding b_i scalar value in the vector v.

Is there a way to do this with normal pytorch operations?

1 Like

Try this:

v = v.view(-1, 1, 1) # same number of dimension as *t*
ans = v * t
1 Like