I have a question regarding my code (sorry if it is really easy or stupid, I have never coded before and tried this for a project). I tried running a probability weighting function for certain probability vector. I however get an error and I do not know how to fix it. When i run the argument of the function first seperatly and then call it in the function it works, but why does it not work in the function itself? Code Below
I hope you can help me. Thanks a lot!
import numpy as np
p = np.arange(0.01, 1, 0.01) # probalities equaly spread between 0 & 1 in steps of 0.01
alpha_1 = 0.5
alpha = np.zeros((1, 99)) + alpha_1 # vector of same length as p with all entries being 0.5
term_in_exopnential_of_weighting_function = - (- np.log(p))**alpha
w = np.exp(term_in_exopnential_of_weighting_function) # weighted probability function
# probability weighting function
#w(p)=np.exp(-(- np.log(p))**alpha)
# --> error, but why?`
It looks like what you're trying to do is to create a function which is named
w
. In Python the syntax for a function definition isThen you can call the function as
f(1, 2, 3)
or whatever fora
,b
, andc
.In the example you gave, I think maybe what you need is
Where
>>>
is the Python interpreter input prompt. Note that the function body must be indented, as enforced by the interpreter. The...
with nothing following it means I just hit theEnter
key without typing anything. With that definition ofw
, I get the following result, givenalpha
andp
as you specified: