Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use "e" (Euler's number) and power operation in python 2.7

How can i write x.append(1-e^(-value1^2/2*value2^2)) in python 2.7?

I don't know how to use power operator and e.

like image 254
Thanos Smar Avatar asked Aug 25 '16 20:08

Thanos Smar


People also ask

How do you represent e to the power in Python?

The Python Math Library comes with the exp() function that we can use to calculate the power of e . For example, ex, which means the exponential of x. The value of e is 2.718281828459045.

How do you code Euler's number in Python?

The two main ways to get the value of e in Python is: using math. e , and. using the built-in exp() function.

Does Python recognize e?

Python has math library and has many functions regarding it. One such function is exp(). This method is used to calculate the power of e i.e. e^y or we can say exponential of y. The value of e is approximately equal to 2.71828…..


1 Answers

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.

like image 145
Moinuddin Quadri Avatar answered Sep 21 '22 13:09

Moinuddin Quadri