pytorch: how to multiply 3d tensor with 2d tensor
I got a 3D tensor three and a 2D tensor two, which need to be multiplied. For example, the dimensions are:
three.shape = 4x100x700
two.shape = 4x100

Output shape should be:
output.shape = 4x100x700

So basically, in output[a,b] there should be 700 scalars which were computed by multiplying all 700 scalars from three[a,b] with the single scalar from two[a,b].

You can simply add an extra dimension to two:
output = three * two.unsqueeze(-1)

There are alternative syntax, e.g.:
output = three * two[..., None]

