Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

SciPy · Function

special.expit

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.

How it works

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.

Syntax

scipy.special.expit(x, out=None)

Parameters

NameTypeDescription
xndarrayThe ndarray to apply expit to element-wise.
outndarray, optionalOptional output array for the function values.

Returns

A scalar or ndarray containing expit of the corresponding input values; for ndarray input, it has the same shape as x.

Key points

  • expit is SciPy's ndarray-oriented implementation of the logistic sigmoid.
  • Its mathematical mapping is the sigmoid formula 1/(1+exp(-x)).
  • expit and logit form an inverse pair on valid finite-domain values.
  • Each input element is transformed independently rather than requiring a single scalar value.
  • An optional out array lets callers direct computed values into supplied storage.
  • For ndarray input, the output retains the input shape.

Common mistakes

  • If using out, provide an appropriately shaped writable array so the element-wise results have somewhere to be stored.

Example: Apply expit to an array

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.

When to use it

Probability-like transformations

Convert model scores or linear predictors into values between zero and one.

Vectorized array computation

Transform batches of numeric inputs efficiently with NumPy-compatible array semantics.

Controlled output storage

Reuse preallocated memory during repeated numerical operations.

Interview questions

QWhat does scipy.special.expit compute?

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.

QHow does expit handle array inputs?

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.

QWhat is the purpose of the out parameter?

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

Source: scipy.special.expit. Checked 2026-10-15.