Complex Data Types and Functions

Many routines in the Python/Numeric Library require complex numbers as input, or return complex numbers as output. Input and output values are Python complex numbers, or lists of complex numbers.

Scalar complex values are expressed as follows: x+ij, for example: 3.0+5.1j.

Arrays of complex numbers can be created as lists or lists of lists, for example: [3+2j, 3+4j] (single-dimensional array), or [[1+2j, 3+4j, 5+6j], [6+5j, 4+3j, 2+1j]] (two-dimensional array).

To access the real and imaginary parts of a Python complex number, use the .real and .imag suffixes. For example:

print("real:", a.real, ", imaginary:", a.imag")

If complex numbers are passed to a user function, they will be passed using a ctypes data structure with “.re” and “.im” suffixes, instead of “.real” and “.imag”. For example:

print("real:", a.re, ", imaginary:", a.im)