How can I convert mutiple arrays with different length to 2d-tensor

Hi. I’m new to pytorch.

Give three different sized long typed 1d-tensor, for example
[2,3,4]
[1]
[1,2,3,4]

how can I combine them efficiently to a 2d-tensor as follow:
[
[2,3,4,0],
[1,0,0,0],
[1,2,3,4]
]
?

torch.nn.utils.rnn.pad_sequence — PyTorch 2.0 documentation is exactly what you are seeking for.