Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

NumPy · Type Alias

np.complex128

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.

How it works

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.

Syntax

numpy.complex128

Key points

  • np.complex128 is an alias for NumPy's cdouble type.
  • Its precision is compatible with Python's built-in complex-number type.
  • NumPy identifies this complex dtype with the character code D.
  • The documented canonical name is numpy.cdouble; numpy.complex128 is the sized alias.

Common mistakes

  • The type uses two double-precision components and is compatible with Python's built-in complex; it is not a quadruple-precision complex type.

Example: Create a complex128 array

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.

When to use it

Complex numerical arrays

Store complex-valued measurements or simulation results in arrays with a fixed NumPy dtype.

Explicit dtype selection

Request predictable complex precision when constructing or converting arrays.

Dtype introspection

Inspect or compare NumPy scalar and dtype representations in generic numerical code.

Interview questions

QWhat does 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).

QHow is 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.

QWhy might an array use 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.cdouble
  • numpy.clongdouble
  • numpy.dtype
  • numpy.complexfloating
  • numpy.complex_

Source: Scalars — NumPy v2.5 Manual. Checked 2026-10-15.