scipy.special.expit#

scipy.special.expit(x, out=None) = <ufunc 'expit'>#

ndarray 的 Expit (又稱 logistic sigmoid) ufunc。

expit 函數,也稱為 logistic sigmoid 函數,定義為 expit(x) = 1/(1+exp(-x))。它是 logit 函數的反函數。

參數:
xndarray

要逐元素應用 expit 的 ndarray。

outndarray,選用

函數值的選用輸出陣列

回傳值:
純量或 ndarray

與 x 形狀相同的 ndarray。其條目是 x 相應條目的 expit

參見

logit

註解

作為 ufunc,expit 接受許多選用的關鍵字參數。 更多資訊請參閱 ufuncs

在 0.10.0 版本中新增。

範例

>>> import numpy as np
>>> from scipy.special import expit, logit
>>> expit([-np.inf, -1.5, 0, 1.5, np.inf])
array([ 0.        ,  0.18242552,  0.5       ,  0.81757448,  1.        ])

logitexpit 的反函數

>>> logit(expit([-2.5, 0, 3.1, 5.0]))
array([-2.5,  0. ,  3.1,  5. ])

繪製 x 在 [-6, 6] 範圍內的 expit(x)

>>> import matplotlib.pyplot as plt
>>> x = np.linspace(-6, 6, 121)
>>> y = expit(x)
>>> plt.plot(x, y)
>>> plt.grid()
>>> plt.xlim(-6, 6)
>>> plt.xlabel('x')
>>> plt.title('expit(x)')
>>> plt.show()
../../_images/scipy-special-expit-1.png