sign¶
- paddle. sign ( x, name=None ) [source]
-
Returns sign of every element in x: 1 for positive, -1 for negative and 0 for zero.
- Parameters
-
x (Tensor) – The input tensor. The data type can be float16, float32 or float64.
name (str, optional) – Name for the operation (optional, default is None). For more information, please refer to Name.
- Returns
-
The output sign tensor with identical shape and data type to the input
x
. - Return type
-
Tensor
Examples
import paddle x = paddle.to_tensor([3.0, 0.0, -2.0, 1.7], dtype='float32') out = paddle.sign(x=x) print(out) # [1.0, 0.0, -1.0, 1.0]