In this tutorial, we will look at how to get the phase (or the angle) of a complex number in Python with the help of some examples. The phase (or angle) of a complex number is defined as the angle the complex number vector makes with the real axis in the counter-clockwise direction.

## How to get the phase of a complex number in Python?

You can use the `numpy.angle()`

function to get the phase (or the angle) of a complex number in Python. The following is the syntax –

**📚 Discover Online Data Science Courses & Programs (Enroll for Free)**

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

# get the angle of complex number - make sure to import numpy numpy.angle(z, deg=False)

It returns the angle in radians by default. If you want to get the angle in degrees, pass `deg=True`

as an argument to the function.

Note that you can use this function on an array of complex numbers as well. In which case it will return an array of the element-wise angle values for the complex numbers in the array.

## Examples

Let’s now look at some examples of using the `numpy.angle()`

function.

**Upskill your career right now →**

### Example 1 – Get the phase of a complex number in radians

By default, the `numpy.angle()`

function returns the phase angle in radians.

Let’s apply it to three scalar values – a real number, a complex number with non-zero real and imaginary components, and a complex number with a non-zero imaginary component (an imaginary number).

import numpy as np # get the angle of complex number (in radians) print(np.angle(14)) print(np.angle(1+1j)) print(np.angle(3j))

Output:

0.0 0.7853981633974483 1.5707963267948966

We get the angles for each of the complex numbers in radians.

### Example 2 – Get the phase of a complex number in degrees

To get the phase of a complex number in degrees, pass `deg=True`

as an argument to the `numpy.angle()`

function.

Let’s use the same three inputs as the above example.

# get the angle of complex number (in degrees) print(np.angle(14, deg=True)) print(np.angle(1+1j, deg=True)) print(np.angle(3j, deg=True))

Output:

**Upskill your career right now →**

0.0 45.0 90.0

We get the angles of the complex numbers in degrees.

### Example 3 – Get the phase of an array of complex numbers

You can also apply the `numpy.angle()`

function to an array, in which case, it will return a Numpy array of the element-wise phase angles.

Let’s apply this function on a Numpy array.

# element-wise get the angle in array of complex numbers ar = np.array([14, 1+1j, 3j]) np.angle(ar, deg=True)

Output:

array([ 0., 45., 90.])

We get the element-wise array of the angles for the values in the `ar`

array.

## Summary

In this tutorial, we looked at how we can use the `numpy.angle()`

function to get the phase (or angle) of a complex number in Python. The following are the key takeaways from this tutorial.

- The
`numpy.angle()`

function returns the angle of a complex number in radians by default. - To get the angle in degrees, pass
`deg=True`

to the`numpy.angle()`

function. - You can also apply this function on an array, in which case it will return the element-wise angles.

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 Absolute Value of a Complex Number
- Numpy – Get the Complex Conjugate
- 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.**