SciPy

scipy.special.log1p

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

Calculates log(1 + x) for use when x is near zero.

Parameters
xarray_like

Real or complex valued input.

outndarray, optional

Optional output array for the function results.

Returns
scalar or ndarray

Values of log(1 + x).

See also

expm1, cosm1

Examples

>>> import scipy.special as sc

It is more accurate than using log(1 + x) directly for x near 0. Note that in the below example 1 + 1e-17 == 1 to double precision.

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

Previous topic

scipy.special.cotdg

Next topic

scipy.special.expm1