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

Logarithm of the logistic sigmoid function.

The SciPy implementation of the logistic sigmoid function is scipy.special.expit, so this function is called log_expit.

The function is mathematically equivalent to log(expit(x)), but is formulated to avoid loss of precision for inputs with large (positive or negative) magnitude.


The values to apply log_expit to element-wise.

outndarray, optional

Optional output array for the function results

outscalar or ndarray

The computed values, an ndarray of the same shape as x.

See also



As a ufunc, log_expit takes a number of optional keyword arguments. For more information see ufuncs

Added in version 1.8.0.


>>> import numpy as np
>>> from scipy.special import log_expit, expit
>>> log_expit([-3.0, 0.25, 2.5, 5.0])
array([-3.04858735, -0.57593942, -0.07888973, -0.00671535])

Large negative values:

>>> log_expit([-100, -500, -1000])
array([ -100.,  -500., -1000.])

Note that expit(-1000) returns 0, so the naive implementation log(expit(-1000)) return -inf.

Large positive values:

>>> log_expit([29, 120, 400])
array([-2.54366565e-013, -7.66764807e-053, -1.91516960e-174])

Compare that to the naive implementation:

>>> np.log(expit([29, 120, 400]))
array([-2.54463117e-13,  0.00000000e+00,  0.00000000e+00])

The first value is accurate to only 3 digits, and the larger inputs lose all precision and return 0.