How to multiply row-wise by scalar in pytorch?
You need to add a corresponding singleton dimension:
m * s[:, None]
s[:, None]
has size of (12, 1)
when multiplying a (12, 10)
tensor by a (12, 1)
tensor pytoch knows to broadcast s
along the second singleton dimension and perform the "element-wise" product correctly.