Solved by ptrblck in post #2 
              
              
                You could create a mask using cumsum and set the values to zero as seen here: 
x = torch.tensor([1, 6, 1, 9, 3, 2, 6, 2])

indices = torch.tensor([[1,2], [4,6]])
val = torch.tensor([[1, -1], [1, -1]])
mask = torch.zeros_like(x).scatter_(
    0, indices.view(-1), val.view(-1)).cumsum(0).bool()

x[mas…