clip

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) $$

Parameters
  • 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

Returns

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

Return Type:

Variable

Examples

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