user8290579
user8290579

Reputation: 199

How can I properly call the erf function from scipy.special?

I am trying to use the erf function with python and I come across the error:

  File "java.py", line 40, in <module>
    getQ(x) 
  File "java.py", line 13, in getQ
    q = math.log(1.0- erf.erf(math.abs(x)/SQRT2))
AttributeError: 'numpy.ufunc' object has no attribute 'erf'

This is my code:

import math 
from scipy.special import erf 

SQRT2 = math.sqrt(2.0)
x=2
ERRMUL = 1.0

def getQ(x): 
    q = math.log(1.0-erf.erf(math.abs(x)/SQRT2))
    print q
getQ(x)

Is there a specific module I'm supposed to be implementing?

Upvotes: 2

Views: 1665

Answers (1)

MSeifert
MSeifert

Reputation: 152657

You just need to call erf, not erf.erf (which doesn't exist and thus raises the Exception) and it's just abs not math.abs:

def getQ(x): 
    q = math.log(1.0-erf(abs(x)/SQRT2))
    print(q)

Upvotes: 3

Related Questions