Probability-like transformations
Convert model scores or linear predictors into values between zero and one.
SciPy · Function
scipy.special.expit computes the logistic sigmoid element-wise: 1/(1+exp(-x)). It returns a scalar or same-shaped ndarray and supports an optional output array.
expit applies the logistic sigmoid independently to each input element, computing 1/(1+exp(-x)). It accepts an array-like input and can optionally write results into a supplied output array. The result preserves the input shape, and expit is the inverse operation of logit.
scipy.special.expit(x, out=None)| Name | Type | Description |
|---|---|---|
x | ndarray | The ndarray to apply expit to element-wise. |
out | ndarray, optional | Optional output array for the function values. |
A scalar or ndarray containing expit of the corresponding input values; for ndarray input, it has the same shape as x.
import numpy as np
from scipy.special import expit
x = np.array([-np.inf, -1.5, 0.0, 1.5, np.inf])
print(expit(x))
# [0. 0.18242552 0.5 0.81757448 1. ]Applies the logistic sigmoid element-wise to an array, including infinite boundary values.
Convert model scores or linear predictors into values between zero and one.
Transform batches of numeric inputs efficiently with NumPy-compatible array semantics.
Reuse preallocated memory during repeated numerical operations.
expit is a universal function that applies the logistic sigmoid element-wise. Its formula is 1/(1+exp(-x)), and it returns values corresponding to the input elements.
Follow-up: How is it related to logit? logit is the inverse of expit, so applying logit to expit(x) recovers x where the operations are defined.
The documented input is an ndarray, and the function applies expit to each element independently. The returned ndarray has the same shape as the input.
Follow-up: What happens for scalar input? The documented return permits a scalar or ndarray, so scalar input produces a scalar result.
The optional out argument supplies an output array for the function values. Without it, expit creates and returns the result; with it, the results are written to the supplied array.
Follow-up: Why might out be useful? It can let callers reuse preallocated storage when repeatedly applying the ufunc.
scipy.special.logit