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]])
>>> paddle.sgn(x)
Tensor(shape=[2, 4], dtype=complex64, place=Place(cpu), stop_gradient=True,
[[ (0.6000000238418579+0.800000011920929j),
   0j                                     ,
 [ (0.6000000238418579+0.800000011920929j),
   (1+0j)                                 ,
   0j                                     ,
  (-1+0j)                                 ]])