espnet.nets.pytorch_backend.nets_utils.pad_list
Less than 1 minute
espnet.nets.pytorch_backend.nets_utils.pad_list
espnet.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.
- 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.]])