Extracting the real and imaginary parts of an NumPy array of complex numbers Last Updated : 02 Sep, 2020 Improve Improve Like Article Like Save Share Report Numpy library gives us functions such as real() and imag() to find real and imaginary parts of a complex number. real() : To find real part of the complex number imag() : To find imaginary part of the complex number Example 1 : # importing the module import numpy as np # creating a NumPy array complex_num = np.array([-1 + 9j, 2 - 77j, 31 - 25j, 40 - 311j, 72 + 11j]) # traversing the list for i in range(len(complex_num)): print("{}. complex number is {}".format(i + 1, complex_num[i])) print ("The real part is: {}".format(complex_num[i].real)) print ("The imaginary part is: {}\n".format(complex_num[i].imag)) Output : 1. complex number is (-1+9j) The real part is: -1.0 The imaginary part is: 9.0 2. complex number is (2-77j) The real part is: 2.0 The imaginary part is: -77.0 3. complex number is (31-25j) The real part is: 31.0 The imaginary part is: -25.0 4. complex number is (40-311j) The real part is: 40.0 The imaginary part is: -311.0 5. complex number is (72+11j) The real part is: 72.0 The imaginary part is: 11.0 Example 2 : The imaginary value of real number will be 0. # importing the module import numpy as np # creating a NumPy array complex_num = np.array([-1, 31, 0.5]) # traversing the list for i in range(len(complex_num)): print("{}. Number is {}".format(i + 1, complex_num[i])) print ("The real part is: {}".format(complex_num[i].real)) print ("The imaginary part is: {}\n".format(complex_num[i].imag)) Output : 1. Number is -1.0 The real part is: -1.0 The imaginary part is: 0.0 2. Number is 31.0 The real part is: 31.0 The imaginary part is: 0.0 3. Number is 0.5 The real part is: 0.5 The imaginary part is: 0.0 Like Article Suggest improvement Next How to Construct a Complex Tensor With the Given Real and Imaginary Parts in PyTorch? Share your thoughts in the comments Add Your Comment Please Login to comment... Similar Reads Python NumPy - Return real parts if input is complex with all imaginary parts close to zero How to Construct a Complex Tensor With the Given Real and Imaginary Parts in PyTorch? NumPy ndarray.imag() Method | Get Imaginary Part in NumPy Array Replace infinity with large finite numbers and fill NaN for complex input values using NumPy in Python Multiply matrices of complex numbers using NumPy in Python Python program to Return the real part of the complex argument Python NumPy - Replace NaN with zero and fill positive infinity for complex input values Web scraper for extracting emails based on keywords and regions Return the Angle of the Complex Argument in Radians in Python using NumPy Generate Chebyshev series with given complex roots using NumPy in Python Like S shivanshsaxena1 Follow Article Tags : Python numpy-arrayManipulation Python-numpy Python Practice Tags : python