我如何x.append(1-e^(-value1^2/2*value2^2))在 python 2.7 中编写代码?
我不知道如何使用 power operator 和 e。
我如何x.append(1-e^(-value1^2/2*value2^2))在 python 2.7 中编写代码?
我不知道如何使用 power operator 和 e。
Python 的幂运算符是**,欧拉数是math.e,所以:
from math import e
x.append(1-e**(-value1**2/2*value2**2))
只是说:numpy这个也有。math因此,如果您已经这样做了,则无需导入import numpy as np:
>>> np.exp(1)
2.718281828459045
权力是**和e^是math.exp:
x.append(1 - math.exp(-0.5 * (value1*value2)**2))
math.e 或from math import e (= 2.718281…)
math.exp(x)然而,这两个表达式e**x是等价的:
返回 e 的 x 次幂,其中 e = 2.718281... 是自然对数的底。这通常比math.e ** x或更准确pow(math.e, x)。文档.python
对于电源使用**(3**2= 9),不是“^”
“^”是按位异或运算符(& 和,| 或),它在逻辑上与位一起工作。因此,例如10^4=14(可能出乎意料)→ 考虑按位描述:
(0000 1010 ^ 0000 0100 = 0000 1110) 程序化