Complex numerical arrays
Store complex-valued measurements or simulation results in arrays with a fixed NumPy dtype.
NumPy · Type Alias
np.complex128 is NumPy's alias for cdouble, a complex scalar made from two 64-bit floating-point components. It is compatible with Python's built-in complex type and can be used as an array dtype.
np.complex128 names NumPy's cdouble scalar type. Each value is a complex number made from two 64-bit-precision floating-point components, matching Python's built-in complex precision; it can also be passed to np.dtype or an array constructor to request that representation.
numpy.complex128np.complex128 is an alias for NumPy's cdouble type.D.numpy.cdouble; numpy.complex128 is the sized alias.complex; it is not a quadruple-precision complex type.import numpy as np
z = np.array([1 + 2j, 3 - 4j], dtype=np.complex128)
print(z.dtype)
print(z.real)
print(z.imag)Creates an array whose elements use NumPy's double-precision complex type, then accesses its real and imaginary components.
Store complex-valued measurements or simulation results in arrays with a fixed NumPy dtype.
Request predictable complex precision when constructing or converting arrays.
Inspect or compare NumPy scalar and dtype representations in generic numerical code.
np.complex128 represent?np.complex128 is an alias of NumPy's cdouble scalar type. It represents a complex number composed of two 64-bit-precision floating-point numbers and is compatible with Python complex.
Follow-up: How can you request this representation for an array? Pass dtype=np.complex128 to an array constructor or use np.dtype(np.complex128).
np.complex128 related to np.cdouble?The canonical name documented for the underlying type is numpy.cdouble, while numpy.complex128 is listed as an alias. Its character code is D.
Follow-up: What does the character code indicate here? It is NumPy's compact dtype code for this complex floating-point scalar type.
np.complex128 instead of an unspecified complex type?The documentation describes the type as compatible with Python complex, whose precision it matches. This makes it suitable when NumPy arrays need a fixed-size complex dtype corresponding to Python complex values.
Follow-up: What happens when a Python complex is converted to a dtype? NumPy maps Python complex to the complex128 dtype.
numpy.cdoublenumpy.clongdoublenumpy.dtypenumpy.complexfloatingnumpy.complex_