numpy.tanh#

numpy.tanh(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature]) = <ufunc 'tanh'>#

逐元素計算雙曲正切。

等效於 np.sinh(x)/np.cosh(x)-1j * np.tan(1j*x)

參數:
xarray_like

輸入陣列。

outndarray、None 或 ndarray 與 None 的元組,選用

結果儲存的位置。如果提供,則必須具有輸入廣播到的形狀。如果未提供或為 None,則會傳回新分配的陣列。元組(僅可作為關鍵字參數)的長度必須等於輸出數量。

wherearray_like,選用

此條件會廣播到輸入。在條件為 True 的位置,out 陣列將設定為 ufunc 結果。在其他位置,out 陣列將保留其原始值。請注意,如果透過預設 out=None 建立未初始化的 out 陣列,則條件為 False 的位置將保持未初始化。

**kwargs

對於其他僅限關鍵字的參數,請參閱 ufunc 文件

傳回:
yndarray

對應的雙曲正切值。如果 x 是純量,則這是一個純量。

註解

如果提供 out,則函數會將結果寫入其中,並傳回對 out 的參考。(請參閱範例)

參考文獻

[1]

M. Abramowitz 和 I. A. Stegun,《數學函數手冊》。紐約州紐約市:Dover,1972 年,第 83 頁。 https://personal.math.ubc.ca/~cbm/aands/page_83.htm

[2]

維基百科,「雙曲函數」, https://en.wikipedia.org/wiki/Hyperbolic_function

範例

>>> import numpy as np
>>> np.tanh((0, np.pi*1j, np.pi*1j/2))
array([ 0. +0.00000000e+00j,  0. -1.22460635e-16j,  0. +1.63317787e+16j])
>>> # 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.tanh([0.1], out1)
>>> out2 is out1
True
>>> # Example of ValueError due to provision of shape mis-matched `out`
>>> np.tanh(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)