﻿ NumPy: Convert angles from radians to degrees for all elements in a given array - w3resource # NumPy: Convert angles from radians to degrees for all elements in a given array

## NumPy Mathematics: Exercise-23 with Solution

Write a NumPy program to convert angles from radians to degrees for all elements in a given array.

Sample Input: [-np.pi, -np.pi/2, np.pi/2, np.pi]

Sample Solution:-

Python Code:

``````import numpy as np
x = np.array([-np.pi, -np.pi/2, np.pi/2, np.pi])
r1 = np.degrees(x)
assert np.array_equiv(r1, r2)
print(r1)
```
```

Sample Output:

```[-180.  -90.   90.  180.]
```

Python Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

What is the difficulty level of this exercise?

Test your Python skills with w3resource's quiz

﻿

## Python: Tips of the Day

Getting rid of unwanted characters:

You can get rid of whitespaces or any specific character using strip methods in Python. You can use either plain strip for both sides, lstrip for the left side and rstrip for the right side only.

```str="+++Welcome python+++"
str.strip()

print(str)```

Output:

`+++Welcome python+++`