paddle.fluid.layers.clip_by_norm(x, max_norm, name=None)[source]

ClipByNorm Operator.

This operator limits the L2 norm of the input \(X\) within \(max\_norm\). If the L2 norm of \(X\) is less than or equal to \(max\_norm\), \(Out\) will be the same as \(X\). If the L2 norm of \(X\) is greater than \(max\_norm\), \(X\) will be linearly scaled to make the L2 norm of \(Out\) equal to \(max\_norm\), as shown in the following formula:

$$ Out = \frac{max\_norm * X}{norm(X)}, $$

where \(norm(X)\) represents the L2 norm of \(X\).

  • x (Variable) – (Tensor) The input of clip_by_norm op and data type is float32.The number of dimensions must be between [1, 9]

  • max_norm (FLOAT) – (float) The maximum norm value

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


out(Variable): (Tensor) The output of clip_by_norm op with shape as input(X)The data type is float32

Return type



import paddle.fluid as fluid
input =
    name='data', shape=[None, 1], dtype='float32')
reward = fluid.layers.clip_by_norm(x=input, max_norm=1.0)