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

SciPy · Function

special.erf

Computes the error function for real or complex arguments. It is a universal function that returns values elementwise for array inputs and can optionally use a supplied output array.

How it works

Call the universal function with a scalar or array-like input. It evaluates the error function elementwise and can optionally write results into a supplied output array.

Syntax

scipy.special.erf(z, out=None)

Parameters

NameTypeDescription
zndarrayInput array of real or complex values.
outndarray, optionalOptional output array for the function values.

Returns

res: scalar or ndarray — The values of the error function at the given points z.

Key points

  • erf supports both real and complex inputs.
  • Its mathematical definition scales the integral of exp(-t²) from zero to z by 2/√π.
  • The result contains the error-function value for each supplied point.
  • The standard normal CDF can be expressed using erf after scaling the argument by √2.
  • The current documentation reports experimental Array API backend support.

Common mistakes

  • The optional out argument must be suitable for receiving the computed values.

Example: Evaluate erf on an array

import numpy as np
from scipy import special

z = np.array([-1.0, 0.0, 1.0])
print(special.erf(z))

Computes the error function elementwise for a NumPy array.

When to use it

Probability and statistics

Evaluate Gaussian-related integrals or distributions involving the error function.

Elementwise numerical computation

Apply the function to vectors or matrices without writing explicit loops.

Backend experimentation

Use compatible Array API backends when testing SciPy's experimental backend support.

Interview questions

QWhat does scipy.special.erf compute?

scipy.special.erf computes the error function for real or complex arguments. Mathematically, it is defined as 2 divided by the square root of pi times the integral of exp(-t squared) from zero to z.

Follow-up: How is erf related to the standard normal CDF? The documentation gives Phi(z) = 1/2 [1 + erf(z / sqrt(2))].

QWhat are the input and output forms?

The input z is an ndarray, and the result is a scalar or ndarray containing the corresponding error-function values. As a ufunc, it supports elementwise array computation.

Follow-up: How can callers avoid allocating a separate result array? Supply a compatible out array through the optional out parameter.

QWhat is the purpose of the out parameter?

The function accepts an optional out argument. This lets callers provide an output array in which SciPy stores the function values.

Follow-up: What related special functions should you consider for numerical alternatives? erfc, erfcx, erfi, erfinv, erfcinv, and wofz are listed as related functions.

  • erfc
  • erfcx
  • erfi
  • erfinv
  • erfcinv
  • wofz

Source: scipy.special.erf — SciPy v1.18.0 Manual. Checked 2026-10-15.