How can I element-wise 2 Tensors with different dimensions with Broadcasting?
I have a tensor called inputs with a size of torch.Size([20, 1, 161, 199]) and another mask with a size of torch.Size([20, 1, 199]). I want to multiply them together.

I tried:

masked_inputs = inputs * mask[..., None]


but get an error:

RuntimeError: The size of tensor a (161) must match the size of tensor b (199) at non-singleton dimension 2


I'm not quite sure what to do?

This did it:

masked_inputs = inputs * mask.unsqueeze(2)

