Process complex signals
Separate phase-related or quadrature data from complex-valued numerical arrays.
NumPy · Pipe
ndarray.imag gives the imaginary component of an array. It returns a view for complex arrays, zeros with the same dtype for non-complex arrays, and elementwise values for object arrays.
Accessing an ndarray’s imag attribute produces the imaginary component element by element. Complex arrays expose this as a view into the source array, while non-complex arrays produce zeros with the same dtype; object arrays use each element’s imag attribute when available.
ndarray.imagAn ndarray containing the imaginary part; for complex arrays it is a view, for non-complex arrays it is zeros of the same dtype, and for object arrays it is elementwise .imag or 0 when unavailable.
import numpy as np
x = np.sqrt(np.array([1 + 0j, 0 + 1j]))
print(x.imag) # [0. 0.70710678]
print(x.imag.dtype) # float64This extracts the imaginary values from a complex array and displays the resulting values and dtype.
Separate phase-related or quadrature data from complex-valued numerical arrays.
Inspect whether complex computations produced expected imaginary components.
Read per-object imaginary values when arrays use object dtype.
ndarray.imag is an attribute that extracts an array’s imaginary part. For complex arrays, the result is a view of the original array.
Follow-up: What happens for a real-valued array? It returns a zero array with the same dtype rather than a complex result.
A complex array’s imag result shares storage with the source array. Therefore, modifying that result may modify the corresponding imaginary components of the source.
Follow-up: How does this differ from object arrays? Object arrays evaluate each element’s imag attribute independently, falling back to zero when absent.
For non-complex arrays, imag returns zeros with the original array’s dtype. For object arrays, it instead obtains each element’s imag value or uses zero if unavailable.
Follow-up: What dtype should be expected for a complex input? It is determined by the complex array’s component representation, as illustrated by the documented float64 example.
numpy.ndarray.realnumpy.imagnumpy.ndarray