numpy.tan#
- numpy.tan(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature]) = <ufunc 'tan'>#
逐元素計算正切值。
相當於逐元素的
np.sin(x)/np.cos(x)
。- 參數:
- xarray_like
輸入陣列。
- outndarray, None 或 ndarray 和 None 的元組, 可選
儲存結果的位置。如果提供,則必須具有輸入廣播到的形狀。如果未提供或為 None,則返回新分配的陣列。元組(可能僅作為關鍵字參數)的長度必須等於輸出的數量。
- wherearray_like, 可選
此條件會廣播到輸入。在條件為 True 的位置,out 陣列將設定為 ufunc 結果。在其他位置,out 陣列將保留其原始值。請注意,如果透過預設
out=None
建立未初始化的 out 陣列,則其中條件為 False 的位置將保持未初始化。- **kwargs
對於其他僅限關鍵字參數的引數,請參閱 ufunc 文件。
- 返回:
- yndarray
對應的正切值。如果 x 是純量,則這是一個純量。
註解
如果提供 out,函數會將結果寫入其中,並返回對 out 的參考。(請參閱範例)
參考文獻
M. Abramowitz 和 I. A. Stegun,《數學函數手冊》。紐約州紐約市:Dover,1972 年。
範例
>>> import numpy as np >>> from math import pi >>> np.tan(np.array([-pi,pi/2,pi])) array([ 1.22460635e-16, 1.63317787e+16, -1.22460635e-16]) >>> >>> # Example of providing the optional output parameter illustrating >>> # that what is returned is a reference to said parameter >>> out1 = np.array([0], dtype='d') >>> out2 = np.cos([0.1], out1) >>> out2 is out1 True >>> >>> # Example of ValueError due to provision of shape mis-matched `out` >>> np.cos(np.zeros((3,3)),np.zeros((2,2))) Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: operands could not be broadcast together with shapes (3,3) (2,2)