I am very appreciate for your reply!!!
I do want get the tensor

tensor([[2., 9.],

[7., 0.],

[8., 0.],

[4., 0.]])
input = torch.Tensor([2, 9, 7, 8, 4])
The index  tensor([0, 0, 1, 2, 3])  is just the raw index you can find, here I do not give the column index!
From index tensor, we can find out that\ the 0th raw has the max length 2 because 0 repeated twice in index tensor , others are just 1, so in order to fill the desired tensor, there are some 0 value in desired tensor!