scipy.special.expit#
- scipy.special.expit(x, out=None) = <ufunc 'expit'>#
expit(又称逻辑 S 型函数)用于 ndarray 的通用函数。
expit 函数,又称逻辑 S 型函数,定义为
expit(x) = 1/(1+exp(-x))
。它是 logit 函数的逆。- 参数:
- xndarray
逐元素应用 expit 的 ndarray。
- outndarray, 可选
用于函数值的可选输出数组
- 返回:
- 标量或 ndarray
一个与 x 形状相同的 ndarray。其条目是 x 相应条目的
expit
。
另请参阅
备注
作为一个通用函数,expit 接受许多可选的关键字参数。有关更多信息,请参阅 通用函数
在版本 0.10.0 中添加。
expit
除了 NumPy 之外,还对兼容 Python 数组 API 标准的后端提供了实验性支持。请考虑通过设置环境变量SCIPY_ARRAY_API=1
并提供 CuPy、PyTorch、JAX 或 Dask 数组作为数组参数来测试这些功能。支持以下后端和设备(或其他功能)组合:库
CPU
GPU
NumPy
✅
不适用
CuPy
不适用
✅
PyTorch
✅
✅
JAX
✅
✅
Dask
✅
不适用
有关更多信息,请参阅 对数组 API 标准的支持。
示例
>>> 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. ])
>>> 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()