ZeroPad1D

class paddle.nn. ZeroPad1D ( padding, data_format='NCL', name=None ) [source]

This interface is used to construct a callable object of the ZeroPad1D class. Pads the input tensor boundaries with zero.

Parameters
  • padding (Tensor | List[int] | int) – The padding size with data type int. If is int, use the same padding in all dimensions. Else [len(padding)/2] dimensions of input will be padded. The pad has the form (pad_left, pad_right).

  • data_format (str) – An string from: “NCL”, “NLC”. Specify the data format of the input data. Default is “NCL”

  • name (str, optional) – The default value is None. Normally there is no need for user to set this property. For more information, please refer to Name.

Shape:
  • x(Tensor): The input tensor of zeropad1d operator, which is a 3-D tensor. The data type can be float32, float64.

  • output(Tensor): The output tensor of zeropad1d operator, which is a 3-D tensor. The data type is same as input x.

Examples

>>> import paddle
>>> import paddle.nn as nn

>>> input_shape = (1, 2, 3)
>>> pad = [1, 2]
>>> data = paddle.arange(paddle.prod(paddle.to_tensor(input_shape)), dtype="float32").reshape(input_shape) + 1
>>> my_pad = nn.ZeroPad1D(padding=pad)
>>> result = my_pad(data)
>>> print(result)
Tensor(shape=[1, 2, 6], dtype=float32, place=Place(cpu), stop_gradient=True,
[[[0., 1., 2., 3., 0., 0.],
  [0., 4., 5., 6., 0., 0.]]])
forward ( x )

forward

Defines the computation performed at every call. Should be overridden by all subclasses.

Parameters
  • *inputs (tuple) – unpacked tuple arguments

  • **kwargs (dict) – unpacked dict arguments

extra_repr ( )

extra_repr

Extra representation of this layer, you can have custom implementation of your own layer.