Python's power operator is **
and Euler's number is math.e
, so:
from math import e
x.append(1-e**(-value1**2/2*value2**2))
Power is **
and e^
is math.exp
:
x.append(1 - math.exp(-0.5 * (value1*value2)**2))
math.e
or from math import e
(= 2.718281…)
The two expressions math.exp(x)
and e**x
are equivalent
however:
Return e raised to the power x, where e = 2.718281… is the base of natural logarithms. This is usually more accurate than math.e ** x
or pow(math.e, x)
. docs.python
for power use **
(3**2
= 9), not " ^ "
" ^ " is a bitwise XOR operator (& and, | or), it works logicaly with bits.
So for example 10^4
=14 (maybe unexpectedly) ? consider the bitwise depiction:
(0000 1010 ^ 0000 0100 = 0000 1110) programiz
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
Source: Stackoverflow.com