Solved by ptrblck in post #2 
              
              
                This code should work: 
idx_v = torch.tensor([1,2,4,0,3])
A = torch.tensor([[1, 1, 1, 1, 1],
                  [1, 1, 1, 1, 1],
                  [1, 1, 1, 1, 1],
                  [1, 1, 1, 1, 1],
                  [1, 1, 1, 1, 1]])

torch.arange(idx_v)
res = torch.zeros_like(A).scatter_(1, idx_v.u…