6
$\begingroup$

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.

$\endgroup$
1
  • 3
    $\begingroup$ How about np.real(-1j * sp.special.erf(1j * x))? $\endgroup$
    – datageist
    Commented Aug 29, 2012 at 2:01

3 Answers 3

5
$\begingroup$

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/

$\endgroup$
1
  • $\begingroup$ 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. $\endgroup$
    – none
    Commented Aug 29, 2012 at 1:35
5
$\begingroup$

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

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

$\endgroup$
5
$\begingroup$

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).

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.