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 –

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

### 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:

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