Premium problem109. Pad Variable-Length Sequences

Medium Locked

sequences is a list of 1-D tensors of differing lengths. Return one batch-first 2-D tensor padded with zeros to the longest length, so [[1,2,3], [4], [5,6]] becomes

[[1, 2, 3],
 [4, 0, 0],
 [5, 6, 0]]

Padding goes on the right, and the row order is the list order.

Input

[tensor([1., 2., 3.]), tensor([4.]), tensor([5., 6.])]

Output

tensor([[1., 2., 3.],
        [4., 0., 0.],
        [5., 6., 0.]])

Premium problem

This one's part of Premium. Unlock the full PyTorch track plus every other premium problem on the site.

Implement solve(...)