# AvgPool1D¶

class paddle.nn. AvgPool1D ( kernel_size, stride=None, padding=0, exclusive=True, ceil_mode=False, name=None ) [source]

This operation applies a 1D average pooling over an input signal composed of several input planes, based on the input, output_size, return_mask parameters. Input(X) and output(Out) are in NCL format, where N is batch size, C is the number of channels, L is the length of the feature. The output tensor shape will be [N, C, output_size].

The output value of the layer with input size (N, C, L), output (N, C, $$L_{out}$$) and kernel_size ksize can be precisely described as For average pool1d:

$Output(N_i, C_i, l) = \frac{Input[N_i, C_i, stride \times l:stride \times l+k]}{ksize}$
Parameters
• kernel_size (int|list|tuple) – The pool kernel size. If pool kernel size is a tuple or list, it must contain an integer.

• stride (int|list|tuple, optional) – The pool stride size. If pool stride size is a tuple or list, it must contain an integer. Default None, then stride will be equal to the kernel_size.

• exclusive (bool, optional) – Whether to exclude padding points in average pooling mode, default is True.

• ceil_mode (bool, optional) – \${ceil_mode_comment}Whether to use the ceil function to calculate output height and width. If it is set to False, the floor function will be used. The default value is False.

• name (str, optional) – For eed to detailed information, please refer to Name. Usually name is no nset and None by default.

Returns

A callable object of AvgPool1D.

Raises
• ValueError – If padding is a string, but not “SAME” or “VALID”.

• ValueError – If padding is “VALID”, but ceil_mode is True.

• ValueError – If padding is a list or tuple but its length greater than 1.

• ShapeError – If the input is not a 3-D tensor.

• ShapeError – If the output’s shape calculated is not greater than 0.

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

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

Examples

import paddle
import paddle.nn as nn
import numpy as np

data = paddle.to_tensor(np.random.uniform(-1, 1, [1, 3, 32]).astype(np.float32))
AvgPool1D = nn.AvgPool1D(kernel_size=2, stride=2, padding=0)
pool_out = AvgPool1D(data)
# pool_out shape: [1, 3, 16]

forward ( x )

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 representation of this layer, you can have custom implementation of your own layer.