You can use exp(x) function of math library, which is same as e^x. Hence you may write your code as:
import math
x.append(1 - math.exp( -0.5 * (value1*value2)**2))
I have modified the equation by replacing 1/2 as 0.5. Else for Python <2.7, we'll have to explicitly type cast the division value to float because Python round of the result of division of two int as integer. For example: 1/2 gives 0 in python 2.7 and below.
Videos
You can use exp(x) function of math library, which is same as e^x. Hence you may write your code as:
import math
x.append(1 - math.exp( -0.5 * (value1*value2)**2))
I have modified the equation by replacing 1/2 as 0.5. Else for Python <2.7, we'll have to explicitly type cast the division value to float because Python round of the result of division of two int as integer. For example: 1/2 gives 0 in python 2.7 and below.
Just saying: numpy has this too. So no need to import math if you already did import numpy as np:
>>> np.exp(1)
2.718281828459045
The function you're using is known as the sigmoid function. You can build a function that will calculate every sigmoid of x.
In order to use e^(x) you can use the numpy function exp as shown in the example.
Copyimport numpy as np
def sigmoid(x):
return 1/(1+np.exp(-x))
if __name__ == '__main__':
age = 15
result = sigmoid(-6.78+(0.04*age))
print(result)
Use math.e:
Copyimport math
1 / (1+ math.e-(-6.78+(0.04*age)))