Solved by Nikronic in post #2 
              
              
                Hi, 
You can do this by creating binary mask. 
First we create a matrix with same shape as X filled with zeros, then put 1s where index matches with ind tensor and finally by using cumsum, set 1 after previously located points. Finally, we can mask X: 
X = torch.tensor(
    [[1,0,4,5,6],
     [3,6,7…