Convert a radian array to degrees in Python

PythonNumpyServer Side ProgrammingProgramming

To convert a radian array to degrees, use the numpy.degrees() method in Python Numpy. The 1st parameter is an input array in radians. The 2nd and 3rd parameters are optional. The 2nd parameter is an ndarray, A location into which the result is stored. If provided, it must have a shape that the inputs broadcast to. If not provided or None, a freshly-allocated array is returned.

The 3rd parameter is the condition is broadcast over the input. At locations where the condition is True, the out array will be set to the ufunc result. Elsewhere, the out array will retain its original value.

Steps

At first, import the required library −

import numpy as np

Create an Array −

arr = np.arange(12.)

Displaying our array −

print("Array...
",arr)

Get the datatype −

print("
Array datatype...
",arr.dtype)

Get the dimensions of the Array −

print("
Array Dimensions...
",arr.ndim)

Get the number of elements of the Array −

print("
Number of elements in the Array...
",arr.size)

Radian array −

res = arr*np.pi/6

To convert a radian array to degrees, use the numpy.degrees() method in Python Numpy. The 1st parameter is an input array in radians −

print("
Radian array to degrees...
",np.degrees(res))

Example

import numpy as np

# Create an Array
arr = np.arange(12.)

# Display the array
print("Array...
", arr) # Get the type of the array print("
Our Array type...
", arr.dtype) # Get the dimensions of the Array print("
Our Array Dimensions...
",arr.ndim) # Get the number of elements in the Array print("
Number of elements...
", arr.size) # Radian array res = arr*np.pi/6 # To convert a radian array to degrees, use the numpy.degrees() method in Python Numpy print("
Radian array to degrees...
",np.degrees(res))

Output

Array...
[ 0. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11.]

Our Array type...
float64

Our Array Dimensions...
1

Number of elements...
12

Radian array to degrees...
[ 0. 30. 60. 90. 120. 150. 180. 210. 240. 270. 300. 330.]
raja
Updated on 25-Feb-2022 06:20:13

Advertisements