scipy.special.log1p

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

计算log(1+x)以在以下情况下使用 x 接近于零。

参数
xarray_like

实数或复数值输入。

outndarray,可选

函数结果的可选输出数组。

退货
标量或ndarray

的值 log(1 + x)

参见

expm1, cosm1

示例

>>> import scipy.special as sc

它比使用 log(1 + x) 直接用于 x 接近0。请注意,在下面的示例中 1 + 1e-17 == 1 达到双倍精度。

>>> sc.log1p(1e-17)
1e-17
>>> np.log(1 + 1e-17)
0.0