Multiply each tensor with a value from a another tensor
I have two tensors:
import torch
a = torch.randn((2,3,5))
b = torch.tensor([[2.0, 1.0, 2.0],[0.5, 1.0, 1.0]])

And I want to multiply the each element in the last dimension in a with the corresponding element in b. That means when a is:
tensor([[[ 1, 2, 3, 4,  5],
     [1, 2,  3,  4,  5],
     [1, 2,  3,  4,  5]],
    [[1, 2,  3,  4,  5],
     [1, 2,  3,  4,  5],
     [1, 2,  3,  4,  5]]])

the result should be:
tensor([[[ 2, 4, 6, 8,  10],
     [1, 2,  3,  4,  5],
     [ 2, 4, 6, 8,  10]],
    [[0.5, 1.0,  1.5,  2.0,  2.5],
     [1, 2,  3,  4,  5],
     [1, 2,  3,  4,  5]]])

How can I do that?

All I need to do, is to add an dimension:
a * b.unsqueeze(-1)

