使用 Python 的 rad2deg() 函数将角度从弧度转换为度数
要将弧度数组转换为度数,请在 Python Numpy 中使用 numpy.rad2deg() 方法。该方法返回相应的角度(以度为单位)。如果 x 是标量,则它是一个标量。第一个参数是输入角度(以弧度为单位)。第二个和第三个参数是可选的。
第二个参数是 ndarray,结果存储到的位置。如果提供,则其形状必须是输入广播到的形状。如果未提供或为 None,则返回一个新分配的数组。
第三个参数是条件,在输入上广播。在条件为 True 的位置,out 数组将设置为 ufunc 结果。在其他地方,out 数组将保留其原始值。
步骤
首先,导入所需的库 -
import numpy as np
创建数组 -
arr = np.arange(12.)
显示我们的数组 -
print("Array...\n",arr)获取数据类型 -
print("\nArray datatype...\n",arr.dtype)
获取数组的维度 -
print("\nArray Dimensions...\n",arr.ndim)获取数组的元素数量 -
print("\nNumber of elements in the Array...\n",arr.size)
弧度数组 -
res = arr*np.pi/6
要将弧度数组转换为度数,请在 Python Numpy 中使用 numpy.rad2deg() 方法。该方法返回相应的角度(以度为单位)。如果 x 是标量,则它是一个标量 -
print("\nRadian array to degrees...\n",np.rad2deg(res))
示例
import numpy as np
# Create an Array
arr = np.arange(12.)
# Display the array
print("Array...\n", arr)
# Get the type of the array
print("\nOur Array type...\n", arr.dtype)
# Get the dimensions of the Array
print("\nOur Array Dimensions...\n",arr.ndim)
# Get the number of elements in the Array
print("\nNumber of elements...\n", arr.size)
# Radian array
res = arr*np.pi/6
# To convert a radian array to degrees, use the numpy.rad2deg() method in Python Numpy
# The method returns the corresponding angle in degrees. This is a scalar if x is a scalar.
print("\nRadian array to degrees...\n",np.rad2deg(res))输出
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.]
广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP