imag

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

Returns a new tensor containing imaginary values of input tensor.

Parameters
  • x (Tensor) – the input tensor, its data type could be complex64 or complex128.

  • name (str, optional) – The default value is None. Normally there is no need for user to set this property. For more information, please refer to Name .

Returns

a tensor containing imaginary values of the input tensor.

Return type

Tensor

Examples

>>> import paddle

>>> x = paddle.to_tensor(
...     [[1 + 6j, 2 + 5j, 3 + 4j], [4 + 3j, 5 + 2j, 6 + 1j]])
>>> print(x)
Tensor(shape=[2, 3], dtype=complex64, place=Place(cpu), stop_gradient=True,
[[(1+6j), (2+5j), (3+4j)],
 [(4+3j), (5+2j), (6+1j)]])

>>> imag_res = paddle.imag(x)
>>> print(imag_res)
Tensor(shape=[2, 3], dtype=float32, place=Place(cpu), stop_gradient=True,
[[6., 5., 4.],
 [3., 2., 1.]])

>>> imag_t = x.imag()
>>> print(imag_t)
Tensor(shape=[2, 3], dtype=float32, place=Place(cpu), stop_gradient=True,
[[6., 5., 4.],
 [3., 2., 1.]])