espnet2.legacy.nets.pytorch_backend.nets_utils.pad_list
Less than 1 minute
espnet2.legacy.nets.pytorch_backend.nets_utils.pad_list
espnet2.legacy.nets.pytorch_backend.nets_utils.pad_list(xs, pad_value)
Perform padding for the list of tensors.
- Parameters:
- xs (List) – List of Tensors [(T_1,
*), (T_2,*), …, (T_B,*)]. - pad_value (float) – Value for padding.
- xs (List) – List of Tensors [(T_1,
- Returns: Padded tensor (B, Tmax,
*). - Return type: Tensor
Examples
>>> x = [torch.ones(4), torch.ones(2), torch.ones(1)]
>>> x
[tensor([1., 1., 1., 1.]), tensor([1., 1.]), tensor([1.])]
>>> pad_list(x, 0)
tensor([[1., 1., 1., 1.],
[1., 1., 0., 0.],
[1., 0., 0., 0.]])