在 Python 中獲取陣列元素的三角反切函式
反正切是一個多值函式:對於每個 x,都有無限多個數字 z 使得 tan(z) = x。# 反正切也稱為 atan 或 tan^{-1}。
慣例是返回實部位於 [-pi/2, pi/2] 範圍內的角度 z。對於實數值輸入資料型別,反正切始終返回實數輸出。對於每個不能表示為實數或無窮大的值,它會產生 nan 並設定無效浮點錯誤標誌。對於複數值輸入,反正切是一個復解析函式,它具有 [1j, infj] 和 [-1j, -infj] 作為分支切割,並且在前者上從左側連續,在後者上從右側連續。
要查詢陣列元素的三角反正切,請在 Python Numpy 中使用 numpy.arctan() 方法。該方法返回 tan 的反函式,因此如果 y = tan(x),則 x = arctan(y)。第一個引數是類陣列。第二個和第三個引數是可選的第二個引數是 ndarray,結果儲存到的位置。如果提供,它必須具有輸入廣播到的形狀。如果未提供或為 None,則返回一個新分配的陣列。元組的長度必須等於輸出的數量。
第三個引數是廣播到輸入上的條件。在條件為 True 的位置,out 陣列將設定為 ufunc 結果。在其他地方,out 陣列將保留其原始值。
步驟
首先,匯入所需的庫 -
import numpy as np
獲取陣列元素的三角反正切。使用 numpy.array() 方法建立陣列 -
arr = np.array((1, -1, 0, 0.3))
顯示我們的陣列 -
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)查詢陣列元素的三角反正切 -
print("\nResult...",np.arctan(arr))示例
import numpy as np
# To find the Trigonometric inverse tangent of the array elements, use the numpy.arctan() method in Python Numpy
# The method returns the The inverse of tan, so that if y = tan(x) then x = arctan(y).
print("Get the Trigonometric inverse tangent of the array elements...\n")
# Array created using the numpy.array() method
arr = np.array((1, -1, 0, 0.3))
# 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)
# Finding the Trigonometric inverse tangent of the array elements
print("\nResult...",np.arctan(arr))輸出
Get the Trigonometric inverse tangent of the array elements... Array... [ 1. -1. 0. 0.3] Our Array type... float64 Our Array Dimensions... 1 Number of elements... 4 Result... [ 0.78539816 -0.78539816 0. 0.29145679]
廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 語言程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP