在Python中獲取反三角正切值
反正切是一個多值函式:對於每個x,都有無限多個z滿足tan(z) = x。習慣上,返回實部位於[-π/2, π/2]範圍內的角度z。反正切也稱為atan或tan⁻¹。
對於實數值輸入資料型別,反正切總是返回實數輸出。對於不能表示為實數或無窮大的每個值,它會產生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
獲取反三角正切。求1的反三角正切:
print("\nResult...",np.arctan(1))求-1的反三角正切:
print("\nResult...",np.arctan(-1))求0的反三角正切:
print("\nResult...",np.arctan(0))
求0.3的反三角正切:
print("\nResult...",np.arctan(0.3))示例
import numpy as np
# To find the Trigonometric inverse tangent, use the numpy.arctan() method in Python Numpy
# The method returns the inverse of tan, so that if y = tan(x) then x = arctan(y).
# A tuple (possible only as a keyword argument) must have length equal to the number of outputs.
print("Get the Trigonometric inverse tangent...")
# finding arctan for 1
print("\nResult...",np.arctan(1))
# finding arctan for -1
print("\nResult...",np.arctan(-1))
# finding arctan for 0
print("\nResult...",np.arctan(0))
# finding arctan for 0.3
print("\nResult...",np.arctan(0.3))輸出
Get the Trigonometric inverse tangent... Result... 0.7853981633974483 Result... -0.7853981633974483 Result... 0.0 Result... 0.2914567944778671
廣告
資料結構
網路
關係型資料庫管理系統(RDBMS)
作業系統
Java
iOS
HTML
CSS
Android
Python
C語言程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP