Padding a tensor until reaching required size
I'm working with certian tensors with shape of (X,42) while X can be in a range between 50 to 70.
I want to pad each tensor that I get until it reaches a size of 70. so all tensors will be (70,42).
is there anyway to do this when I the begining size is a variable X? thanks for the help!

Use torch.nn.functional.pad - Pads tensor.

import torch
import torch.nn.functional as F

source = torch.rand((3,42))
source.shape
&gt;&gt;&gt; torch.Size([3, 42])


# here, pad = (padding_left, padding_right, padding_top, padding_bottom)
source_pad = F.pad(source, pad=(0, 0, 0, 70 - source.shape[0]))


source_pad.shape
&gt;&gt;&gt; torch.Size([70, 42])

