w3resource logo
Python Exercises

Python NumPy: Find the real and imaginary parts of an array of complex numbers

Python NumPy: Array Object Exercise-15 with Solution

Write a Python program to find the real and imaginary parts of an array of complex numbers

Sample Solution:-

Python Code:

import numpy as np
x = np.sqrt([1+0j, 0+1j])
print("Original array",x)
print("Real part of the array:")
print(x.real)
print("Imaginary part of the array:")
print(x.imag)

Sample Output:

Original array [ 1.00000000+0.j          0.70710678+0.70710678j]       
Real part of the array:                                                
[ 1.          0.70710678]                                              
Imaginary part of the array:                                           
[ 0.          0.70710678]

Python Code Editor:

import numpy as np
x = np.sqrt([1+0j, 0+1j])
print("Original array",x)
print("Real part of the array:")
print(x.real)
print("Imaginary part of the array:")
print(x.imag)

Improve this sample solution and post your code through Disqus