Python Practice › NumPy Programs › Program 53
Real and imaginary parts
Write a NumPy program to find the real and imaginary parts of complex numbers.
Input
[6+2j, 10+5j]
Output
Real: [ 6. 10.] Imaginary: [2. 5.]
Approach
.realand.imag.
Solution
import numpy as npa = np.array([6 + 2j, 10 + 5j])print("Real:", a.real, "Imaginary:", a.imag)Output
Real: [ 6. 10.] Imaginary: [2. 5.]
Learn the concept
New to this topic? Read the lesson, then come back.