scipy.special.log1p — SciPy v1.15.3 Manual (original) (raw)

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).

Examples

import numpy as np import scipy.special as sc

It is more accurate than using log(1 + x) directly for xnear 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