isreal

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

Tests if each element of input is a real number or not.

Parameters
  • x (Tensor) – The input Tensor.

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

Returns

out (Tensor), The output Tensor. Each element of output indicates whether the input element is a real number or not.

Examples

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

>>> x = paddle.to_tensor([(-0.+1j), (-2.1+0.2j), (2.5-3.1j)])
>>> res = paddle.isreal(x)
>>> print(res)
Tensor(shape=[3], dtype=bool, place=Place(cpu), stop_gradient=True,
[False, False, False])

>>> x = paddle.to_tensor([(-0.+1j), (-2.1+0j), (2.5-0j)])
>>> res = paddle.isreal(x)
>>> print(res)
Tensor(shape=[3], dtype=bool, place=Place(cpu), stop_gradient=True,
[False, True, True])