Python Practice › NumPy Programs › Program 53

Real and imaginary parts

EasyNumPy Programs · 53 of 100

Write a NumPy program to find the real and imaginary parts of complex numbers.

Advertisement
Input
[6+2j, 10+5j]
Output
Real: [ 6. 10.] Imaginary: [2. 5.]

Approach

  1. .real and .imag.

Solution

Python
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.

More numpy programs

← All 100 NumPy Programs

Leave a Comment