使用 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