Solved by ptrblck in post #4 
              
              
                Ok, thanks for the info. 
I don’t know an elegant way to achieve your results. 
If your results would look like this: 
l  = tensor([10, 3, 1, 0, 0, 0, 0, 0, 0, 0]),
m_l = tensor([0, 0, 0, 20, 4, 0, 0, 0, 0, 0,])

, i.e. there the zeros in front of the right part, you could use .scatter_(). 
In case …