signbit

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

Tests if each element of input has its sign bit set or not.

Parameters
  • x (Tensor) – The input Tensor. Must be one of the following types: float16, float32, float64, bfloat16, uint8, int8, int16, int32, int64.

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

Returns

The output Tensor. The sign bit of the corresponding element of the input tensor, True means negative, False means positive.

Return type

out (Tensor)

Examples

>>> import paddle
>>> paddle.set_device('cpu')
>>> x = paddle.to_tensor([-0., 1.1, -2.1, 0., 2.5], dtype='float32')
>>> res = paddle.signbit(x)
>>> print(res)
Tensor(shape=[5], dtype=bool, place=Place(cpu), stop_gradient=True,
[True, False, True, False, False])
>>> import paddle
>>> paddle.set_device('cpu')
>>> x = paddle.to_tensor([-5, -2, 3], dtype='int32')
>>> res = paddle.signbit(x)
>>> print(res)
Tensor(shape=[3], dtype=bool, place=Place(cpu), stop_gradient=True,
[True , True , False])