NumPy angle()
The numpy.angle() function returns the phase (angle) of a complex number in radians (default) or degrees.
Syntax
</>
Copy
numpy.angle(z, deg=False)
Parameters
| Parameter | Type | Description |
|---|---|---|
z | array_like | A complex number or an array of complex numbers. |
deg | bool, optional | Returns the angle in degrees if True, otherwise in radians (default). |
Return Value
Returns an ndarray or scalar containing the counterclockwise angle (phase) from the positive real axis on the complex plane. The range of values is (-π, π] in radians or (-180, 180] degrees if deg=True.
Examples
1. Computing the Angle of a Single Complex Number
Here, we compute the phase angle of a single complex number.
</>
Copy
import numpy as np
# Define a complex number
z = 1 + 1j # Complex number (1 + i)
# Compute the angle in radians
angle_rad = np.angle(z)
# Print the result
print("Angle in radians:", angle_rad)
Output:
Angle in radians: 0.7853981633974483
