Complex Number Functions

TensorFlow provides several operations that you can use to add complex number functions to your graph.

tf.complex(real, imag, name=None)

Converts two real numbers to a complex number.

Given a tensor real representing the real part of a complex number, and a tensor imag representing the imaginary part of a complex number, this operation returns complex numbers elementwise of the form \(a + bj\), where a represents the real part and b represents the imag part.

The input tensors real and imag must have the same shape.

For example:

# tensor 'real' is [2.25, 3.25]
# tensor `imag` is [4.75, 5.75]
tf.complex(real, imag) ==> [[2.25 + 4.75j], [3.25 + 5.75j]]
Args:
  • real: A Tensor. Must be one of the following types: float32, float64.
  • imag: A Tensor. Must have the same type as real.
  • name: A name for the operation (optional).
Returns:

A Tensor of type complex64 or complex128.


tf.conj(x, name=None)

Returns the complex conjugate of a complex number.

Given a tensor input of complex numbers, this operation returns a tensor of complex numbers that are the complex conjugate of each element in input. The complex numbers in input must be of the form \(a + bj\), where a is the real part and b is the imaginary part.

The complex conjugate returned by this operation is of the form \(a - bj\).

For example:

# tensor 'input' is [-2.25 + 4.75j, 3.25 + 5.75j]
tf.conj(input) ==> [-2.25 - 4.75j, 3.25 - 5.75j]

If x is real, it is returned unchanged.

Args:
  • x: Tensor to conjugate. Must have numeric type.
  • name: A name for the operation (optional).
Returns:

A Tensor that is the conjugate of x (with the same type).

Raises:
  • TypeError: If x is not a numeric tensor.

tf.imag(input, name=None)

Returns the imaginary part of a complex number.

Given a tensor input of complex numbers, this operation returns a tensor of type float32 or float64 that is the imaginary part of each element in input. All elements in input must be complex numbers of the form (a + bj), where a is the real part and b is the imaginary part returned by this operation.

For example:

# tensor 'input' is [-2.25 + 4.75j, 3.25 + 5.75j]
tf.imag(input) ==> [4.75, 5.75]
Args:
  • input: A Tensor. Must be one of the following types: complex64, complex128.
  • name: A name for the operation (optional).
Returns:

A Tensor of type float32 or float64.


tf.real(input, name=None)

Returns the real part of a complex number.

Given a tensor input of complex numbers, this operation returns a tensor of type float32 or float64 that is the real part of each element in input. All elements in input must be complex numbers of the form \(a + bj\), where a is the real part returned by this operation and b is the imaginary part.

For example:

# tensor 'input' is [-2.25 + 4.75j, 3.25 + 5.75j]
tf.real(input) ==> [-2.25, 3.25]

If input is already real, it is returned unchanged.

Args:
  • input: A Tensor. Must have numeric type.
  • name: A name for the operation (optional).
Returns:

A Tensor of type float32 or float64.