paddle.fluid.layers.clip(x, min, max, name=None)[source]

Clip Operator.

The clip operator limits the value of given input within an interval [min, max], just as the following equation,

$$ Out = MIN(MAX(x, min), max) $$

  • x (Variable) – Tensor, the input of clip op, data type should be float32 or float64

  • min (float) – float number, the minimum value to clip by

  • max (float) – float number, the maximum value to clip by

  • 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


Tensor, the clipped tensor, with the same shape and data type as input(x)

Return Type:



import paddle.fluid as fluid
input =
    name='data', shape=[1], dtype='float32')
reward = fluid.layers.clip(x=input, min=-1.0, max=1.0)