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 uint8, int8, int16, int32, int64, 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)
>>> out
Tensor(shape=[4], dtype=float32, place=Place(cpu), stop_gradient=True,
[ 1.,  0., -1.,  1.])