python 2.7 - Error in exponential PDF -
i need complete function exponentialpdf
error:
'indexerror: index 0 out of bounds axis 0 size 0'
the function looks this:
def uniformpdf(x,a=0.0,b=4.0): p = 1.0/(b-a)*ones((len(x),)) p[x<a] = 0.0 p[x>b] = 0.0 return(p) def exponentialpdf(x,a=1.0): """ call: p = exponentialpdf(x,a) input argument: vals: float (array) output argument: p: float (array) examples: in[1]: exponentialpdf([1,2],3) out[1]: array([ 0.14936121, 0.03332699]) """ p = * exp(-a*x) p[x<0] = 0.0 return(p)
can me error?
sounds list passing in function empty. read python lists , see following post: indexerror: list assignment index out of range
i found function works using numpy array, e.g. p = exponentialpdf(np.array([1,2]),3). hope help, should check out homework post , ask again if you're still stuck.
edit: using numpy, add explicit convert numpy array in function follows:
def exponentialpdf(x,a=1.0): """ call: p = exponentialpdf(x,a) input argument: vals: float (array) output argument: p: float (array) examples: in[1]: exponentialpdf([1,2],3) out[1]: array([ 0.14936121, 0.03332699]) """ if type(x) list: x = array(x) p = * exp(-a*x) p[x<0] = 0.0 return(p)
hopefully fix problem , can use function needed (assuming returning numpy array function okay).
Comments
Post a Comment