clip

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

This operator clip all elements in input into the range [ min, max ] and return a resulting tensor as the following equation:

\[Out = MIN(MAX(x, min), max)\]
Parameters
  • x (Tensor) – An N-D Tensor with data type float32 or float64.

  • min (float32|Tensor) – The lower bound with type float32 or a Tensor with shape [1] and type int32, float32, float64.

  • max (float32|Tensor) – The upper bound with type float32 or a Tensor with shape [1] and type int32, float32, float64.

  • 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

A Tensor with the same data type and data shape as input.

Return type

Tensor

Examples

import paddle

x1 = paddle.to_tensor([[1.2, 3.5], [4.5, 6.4]], 'float32')
out1 = paddle.clip(x1, min=3.5, max=5.0)
out2 = paddle.clip(x1, min=2.5)
print(out1)
# [[3.5, 3.5]
# [4.5, 5.0]]
print(out2)
# [[2.5, 3.5]
# [[4.5, 6.4]