使用 Python 獲取以度為單位的角陣列的三角正切值
三角正切等價於元素級上的 np.sin(x)/np.cos(x)。要獲取以度為單位的角陣列的三角正切值,請在 Python Numpy 中使用 numpy.tan() 方法。該方法返回第一個引數 x 的每個元素的正切值。第一個引數 x 是以弧度表示的角度(2pi 表示 360 度)。這裡,它是一個角陣列。
第二個和第三個引數是可選的。第二個引數是一個 ndarray,結果儲存到其中。如果提供,它必須具有輸入廣播到的形狀。如果未提供或為 None,則返回一個新分配的陣列。元組(僅作為關鍵字引數可能)的長度必須等於輸出的數量。
第三個引數是條件廣播到輸入上。在條件為 True 的位置,out 陣列將設定為 ufunc 結果。在其他地方,out 陣列將保留其原始值。請注意,如果透過預設的 out=None 建立了一個未初始化的 out 陣列,則其中條件為 False 的位置將保持未初始化。
步驟
首先,匯入所需的庫 -
import numpy as np
要查詢 tan 0、tan 30、tan 45、tan 60、tan 90、tan 180、tan -180 的角陣列 -
arr = np.array((0., 30., 45., 60., 90., 180., -180.))
顯示我們的陣列 -
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)
要查詢以度為單位的角陣列的三角正切值,請在 Numpy 中使用 numpy.tan() 方法 -
print("\nResult...",np.tan(arr * np.pi / 180. ))示例
import numpy as np
# Trigonometric tangent is equivalent to np.sin(x)/np.cos(x) elementwise.
# To get the Trigonometric tangent of an array of angles given in degrees, use the numpy.tan() method in Python Numpy
print("The Trigonometric tangent of an array of angles...")
# Array of angles
# finding tan 0, tan 30, tan 45, tan 60, tan 90, tan 180, tan -180.
arr = np.array((0., 30., 45., 60., 90., 180., -180.))
# 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)
# To find the trigonometric tangent of an array of angles given in degrees, use the numpy.tan() method in Numpy
print("\nResult...",np.tan(arr * np.pi / 180. ))輸出
The Trigonometric tangent of an array of angles... Array... [ 0. 30. 45. 60. 90. 180. -180.] Our Array type... float64 Our Array Dimensions... 1 Number of elements... 7 Result... [ 0.00000000e+00 5.77350269e-01 1.00000000e+00 1.73205081e+00 1.63312394e+16 -1.22464680e-16 1.22464680e-16]
廣告
資料結構
網路
關係資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 語言程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP