numpy.arctan#
- numpy.arctan(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature]) = <ufunc 'arctan'>#
三角反正切,逐元素運算。
tan 的反函數,因此若
y = tan(x)
則x = arctan(y)
。- 參數:
- xarray_like(類陣列)
- outndarray、None 或 ndarray 與 None 的 tuple (元組),選用
儲存結果的位置。若提供,其形狀必須能與輸入陣列進行廣播。若未提供或為 None,則會回傳新分配的陣列。tuple (元組) (僅能作為關鍵字引數) 的長度必須等於輸出的數量。
- wherearray_like(類陣列),選用
此條件會廣播至輸入陣列。在條件為 True 的位置,out 陣列會被設為 ufunc 的結果。在其他位置,out 陣列會保留其原始值。請注意,若透過預設的
out=None
建立未初始化的 out 陣列,則其中條件為 False 的位置將保持未初始化。- **kwargs
關於其他僅限關鍵字引數,請參閱 ufunc 文件。
- 回傳值:
- outndarray 或 純量
輸出陣列的形狀與 x 相同。其實部介於
[-pi/2, pi/2]
之間 (arctan(+/-inf)
回傳+/-pi/2
)。若 x 為純量,則此為純量。
註解
arctan
是一個多值函數:對於每個 x,都有無限多個數字 z 使得 tan(z) = x。慣例是回傳實部介於 [-pi/2, pi/2] 的角度 z。對於實數值輸入資料類型,
arctan
總是回傳實數輸出。對於每個無法表示為實數或無限大的值,它會產生nan
並設定 invalid 浮點數錯誤旗標。對於複數值輸入,
arctan
是一個複數解析函數,其分支切割為 [1j, infj
] 和 [-1j, -infj
],且在前者的左側連續,在後者的右側連續。反正切也稱為
atan
或 tan^{-1}。參考文獻
Abramowitz, M. 與 Stegun, I. A., 數學函數手冊,第 10 次印刷,紐約:Dover,1964,第 79 頁。 https://personal.math.ubc.ca/~cbm/aands/page_79.htm
範例
我們預期 0 的 arctan 為 0,而 1 的 arctan 為 pi/4
>>> import numpy as np
>>> np.arctan([0, 1]) array([ 0. , 0.78539816])
>>> np.pi/4 0.78539816339744828
繪製 arctan
>>> import matplotlib.pyplot as plt >>> x = np.linspace(-10, 10) >>> plt.plot(x, np.arctan(x)) >>> plt.axis('tight') >>> plt.show()