# Numpy Angle Explained With Examples

Hello geeks, and welcome to this article. Today, we will cover the NumPy angle(). Along with that, for an overall better understanding, we will also look at its syntax and parameters. Then, we will see the application of all the theory parts through a couple of examples. But at first, let us try to get a brief understanding of the function through its definition.

Suppose you want to find out the angle of a complex argument. Then, in that case, the function NumPy angle() comes handy and helps us achieve our output. We will develop more clarity about it as we move ahead in the article. In the next section, we will be looking at the syntax associated with it.

Contents

## Syntax

``numpy.angle(z, deg="")``

This is the general syntax of our function. In the next section, we will discuss the parameters and associated return value.

## Parameters

1. Z: Array_like

This parameter represents the complex argument or the complex number corresponding to which the angle needs to be calculated.

2. Deg:bool

This is an optional parameter. By default, it is set to “false”. In that case, it returns the angle in radians. In case you set it to “true,” we get the angle in degrees.

## Return

angles: ndarray or scalar

It returns the counterclockwise angle from the positive real axis on completion of the program.

## Examples Covering Numpy Angle

We have covered all the necessary theories associated with our function. Also, we have looked at its definition and developed a brief understanding of our function. In this section, we will look at various examples to help us better understand our function. We will start with an elementary-level example and gradually move our way to more complicated examples.

```#input
import numpy as ppool

print(ppool.angle((1+1j),deg="true"))
```

Output:

``45.0``

In the above example, at first, we have imported the NumPy module. Then, we used our syntax to obtain the desired output. Here, we have specified the degree to be true and get the output in degree. Here, the output justifies our input. We can understand it as follows. We have considered (1+1j) as our complex number. Here a=1(real part) and b=1(complex part). Then we also know that tan(θ)=b/a in that case. Concerning our condition, we have a tan(θ)=1/1=45 degrees. Hence justified.

We can also use this function for an array of numbers. We will see that in the next example.

```#input
import numpy as ppool
a=[1+2j,1,1j,3+4j]
print(ppool.angle(a,deg="true"))
```

Output:

``[63.43494882  0.         90.         53.13010235]``

In this example, we have followed all the steps similar to that of the first one. But here, instead of a single value, we have used an array. The output in all the cases justifies our input; hence, we can say it is verified. If you want, you can cross-check, as I did in the first example.

Why don’t you try for the complex numbers of your choice and tell me what result you got?

## Limitations of Numpy Angle

The function NumPy angle is a really nice function. But it, too, has its own limitations. As per the definition, it only helps us in calculating the angle between the complex arguments.

This means we cannot use this function to calculate the angle value between 2 points or vectors. It works great in its domain, but outside that, it is of no great use.

## What is a vector, and how do you calculate the angle between two vectors using the numpy angle?

Vectors are generally defined as the physical quantities that, along with a magnitude, have a direction associated with them. Elementary examples of a vector are displacement, velocity, etc. The vectors are generally represented using symbolic representation like î(along the x-axis), ĵ (along the y-axis), k̂(along the z-axis).

Now, let us try to find out how to calculate the angle between 2 vectors. The general formula to calculate the angle between them is

`[COS (θ)= a.b/|a|.|b|]   (consider an arrow symbol over a and b)`
```import numpy as np
vec1 = [2, 1]
vec2 = [1, 3]

unit1 = vec1 / np.linalg.norm(vec1)
unit2 = vec2 / np.linalg.norm(vec2)
dot_product = np.dot(unit1, unit2)
print(np.arccos(dot_product))
```

Output:

``0.7853981633974484``

In the example, we first imported the NumPy module. Then, we have defined 2 of our arrays between which we want to calculate the angle. Then, we used another function of the NumPy library, which is linalg norm(). This function returns one of an infinite number of vector norms. Then, we used the function arccos, which helps us calculate the cos inverse value. Then, our value is calculated.

## Conclusion

In this article, we covered the NumPy angle(). Besides that, we have also looked at its syntax and parameters. For better understanding, we looked at a couple of examples. We varied the syntax and looked at the output for each case. In the end, we can conclude that NumPy angle() is used to find the angle for a complex argument.

I hope this article was able to clear all doubts. But if you have any unsolved queries, feel free to write them down below in the comment section.