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 float16, float32, float64, int32 or int64.
min (float|int|Tensor, optional) – The lower bound with type
float
,int
or a0-D Tensor
with shape [] and typeint32
,float16
,float32
,float64
.max (float|int|Tensor, optional) – The upper bound with type
float
,int
or a0-D Tensor
with shape [] and typeint32
,float16
,float32
,float64
.name (str, optional) – Name for the operation (optional, default is None). 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]