Premium problem65. Pad a 2D Tensor

Easy Locked

x is a 2-D tensor and padding is the tuple (left, right, top, bottom). Return x padded with zeros by those amounts.

The padding is asymmetric, so a tensor padded by (1, 0, 2, 0) gains one column on the left and two rows on top and nothing on the other sides.

Input

x =
tensor([[1., 2.],
        [3., 4.]])
padding = (1, 1, 1, 1)

Output

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

Premium problem

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

Implement solve(...)