How to multiply a tensor with a vector?
I have 2 tensors 

a = torch.tensor([1,2])
b = torch.tensor([[[10,20],
                   [30,40]],
                  [[1,2],
                   [3,4]]])


and I would like to combine them in such a way that 

a ? b = tensor([[[10,20],
                 [30,40]],
                [[ 2, 4],
                 [ 6, 8]]])


(and then sum over the 0th dimension, in the end I want to do a weighted sum)

I've tried:

""" no idea how to interpret that """
a @ b                                                                                                                                                                                                
tensor([[ 70, 100],
        [  7,  10]])

b @ a                                                                                                                                                                                                
tensor([[ 50, 110],
        [  5,  11]])

for i in range(b.size()[0]): # works but I don't think this will work with autograd 
      b[i] *= a[i] 

a * b              # multiplies right side by 2
tensor([[[10, 40],
         [30, 80]],

        [[ 1,  4],
         [ 3,  8]]])

a.unsqueeze(1)     # multiplies bottom side by 2
tensor([[[10, 20],
         [60, 80]],

        [[ 1,  2],
         [ 6,  8]]])

a.unsqueeze(2) * b # dimension out of range


This should workc = a.unsqueeze(1).unsqueeze(1) * b
