In this tutorial, we will look at how to get the complex conjugate of a complex number in a Numpy array. The complex conjugate of a complex number is obtained by changing the sign of the imaginary part. For example for the complex number a + bj, the complex conjugate would be a - bj.
How to get the complex conjugate of complex values in a Numpy array?

You can use the numpy.conj() function to get (element-wise) the complex conjugate of complex numbers in a Numpy array. The following is the syntax –
# get the complex conjugate - pass scaler value or numpy array np.conj(a)
Note that the numpy.conj() function is an alias for the numpy.conjugate() function (they both return the element-wise complex conjugate of a Numpy array).
If you pass a scalar value, it returns the complex conjugate of that value. And, if you pass a Numpy array, it returns the element-wise array of the complex conjugates.
Examples
Let’s now look at some examples of using the above function on a scalar value and a Numpy array.
Example 1 – Get the complex conjugate for a scalar value using numpy.conj()
First, let’s pass scaler values to the numpy.conj() function.
Let’s apply the numpy.conj() function on three scalar values – a real number, a complex number with a non-zero real part, and a complex number with the real part as 0.
import numpy as np # get the complex conjugate print(np.conj(14)) print(np.conj(2 + 4j)) print(np.conj(3j))
Output:
Introductory ⭐
- Harvard University Data Science: Learn R Basics for Data Science
- Standford University Data Science: Introduction to Machine Learning
- UC Davis Data Science: Learn SQL Basics for Data Science
- IBM Data Science: Professional Certificate in Data Science
- IBM Data Analysis: Professional Certificate in Data Analytics
- Google Data Analysis: Professional Certificate in Data Analytics
- IBM Data Science: Professional Certificate in Python Data Science
- IBM Data Engineering Fundamentals: Python Basics for Data Science
Intermediate ⭐⭐⭐
- Harvard University Learning Python for Data Science: Introduction to Data Science with Python
- Harvard University Computer Science Courses: Using Python for Research
- IBM Python Data Science: Visualizing Data with Python
- DeepLearning.AI Data Science and Machine Learning: Deep Learning Specialization
Advanced ⭐⭐⭐⭐⭐
- UC San Diego Data Science: Python for Data Science
- UC San Diego Data Science: Probability and Statistics in Data Science using Python
- Google Data Analysis: Professional Certificate in Advanced Data Analytics
- MIT Statistics and Data Science: Machine Learning with Python - from Linear Models to Deep Learning
- MIT Statistics and Data Science: MicroMasters® Program in Statistics and Data Science
🔎 Find Data Science Programs 👨💻 111,889 already enrolled
Disclaimer: Data Science Parichay is reader supported. When you purchase a course through a link on this site, we may earn a small commission at no additional cost to you. Earned commissions help support this website and its team of writers.
14 (2-4j) -3j
We get the complex conjugate for all the scalar values irrespective of whether we passed a real or a complex number as an argument.
Example 2 – Element-wise get the complex conjugate in a Numpy array using numpy.conj()
If you apply the numpy.conj() function on an array, it will return a Numpy array of the complex conjugates for the elements inside the array.
Let’s create a 1-D array and apply the numpy.conj() function to it.
# create a numpy array ar = np.array([1, 2+3j, 2+0j, 0+4j, 5.7, np.nan, np.inf, 1j, 0+0j]) # element-wise get the complex conjugate in ar np.conj(ar)
Output:
array([1. -0.j, 2. -3.j, 2. -0.j, 0. -4.j, 5.7-0.j, nan-0.j, inf-0.j,
0. -1.j, 0. -0.j])
We get a Numpy array containing the complex conjugate of each value in the array ar.
Summary
In this tutorial, we looked at how we can use the numpy.conj() function to get the complex conjugate of a complex number in a Numpy array. Keep in mind that if you apply this function on a scalar value, it returns the resulting complex conjugate whereas if you apply it on an array, it returns the array of complex conjugates.
You might also be interested in –
- Practical Guide to Working with Complex Numbers in Python
- Python – Add Two Complex Numbers
- Python – Subtract Two Complex Numbers
- Python – Multiply Two Complex Numbers
- Python – Divide Two Complex Numbers
- Python – Generate a Random Complex Number
- Python – Convert Complex Number to Polar Form
- Python – Get the Phase Angle of a Complex Number
- Python – Get the Absolute Value of a Complex Number
- Numpy – Get the Real Part of a Complex Number
- Numpy – Get the Imaginary Part of a Complex Number
- Numpy – Check If a Number is Real
- Numpy – Check If a Number is Complex
Subscribe to our newsletter for more informative guides and tutorials.
We do not spam and you can opt out any time.
