# What is the best way to get erfi with scipy?

I want this:

http://mathworld.wolfram.com/Erfi.html

But apparently scipy does not have this in its extensive special functions library.

http://docs.scipy.org/doc/scipy/reference/special.html

It is not the same as erfinv. Right now I am using an obscure identity involving the hyp1f1 hypergeometric function but I would rather use a nicer function if possible. Also I'll pre-emptively say that I would rather not deal with complex numbers, because the inputs and outputs are all real.

• How about np.real(-1j * sp.special.erf(1j * x))? – datageist Aug 29 '12 at 2:01

## 3 Answers

Erfi is available from the mpmath library.

See documentation here: http://mpmath.googlecode.com/svn/trunk/doc/build/functions/expintegrals.html#mpmath.erfi

Here is a link to the library: https://code.google.com/p/mpmath/

• Thanks, I'll accept this because it is a good answer and I didn't mention mpmath in my question. I would still be interested to see a better scipy hack. – none Aug 29 '12 at 1:35

The correct answer in SciPy is given by datageist in his comment:

(-1.0j)*scipy.special.erf((-1.0j*x))

Unfortunately, in SciPy 0.11 or earlier, the erf function is rather inaccurate for complex arguments. However, SciPy 0.12 will contain accurate complex erf support and includes an optimized erfi function. Alternatively, you can use the scipy.special.dawsn function, which computes the Dawson function, a scaled erfi function. erfi(x) is then given by (2/sqrt(pi)) * exp(x^2) * dawsn(x).