paddle. sgn ( x, name=None ) [source]

For complex tensor, this API returns a new tensor whose elements have the same angles as the corresponding elements of input and absolute values of one. For other float dtype tensor, this API returns sign of every element in x: 1 for positive, -1 for negative and 0 for zero, same as paddle.sign.

  • x (Tensor) – The input tensor, which data type should be float16, float32, float64, complex64, complex128.

  • name (str, optional) – Name for the operation (optional, default is None). For more information, please refer to Name.


A sign Tensor for real input, or normalized Tensor for complex input, shape and data type are same as input.

Return type



import paddle

x = paddle.to_tensor([[3 + 4j, 7 - 24j, 0, 1 + 2j], [6 + 8j, 3, 0, -2]])
#[[0.6+0.8j       0.28-0.96j      0.+0.j      0.4472136+0.8944272j]
# [0.6+0.8j       1.+0.j          0.+0.j      -1.+0.j]]