sign

paddle. sign ( x: Tensor, name: str | None = None ) Tensor [source]

Returns sign of every element in x: For real numbers, 1 for positive, -1 for negative and 0 for zero. For complex numbers, the return value is a complex number with unit magnitude. If a complex number element is zero, the result is 0+0j.

Parameters
  • x (Tensor) – The input tensor. The data type can be uint8, int8, int16, int32, int64, bfloat16, float16, float32, float64, complex64 or complex128.

  • name (str|None, 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)
>>> out
Tensor(shape=[4], dtype=float32, place=Place(cpu), stop_gradient=True,
[ 1.,  0., -1.,  1.])