math.exp()不适用于复数:
>>> math.exp (math.pi*1j)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: can't convert complex to float这并不会对我造成太大的伤害,因为**的工作原理是:
>>> math.e ** (math.pi*1j)
(-1+1.2246467991473532e-16j)现在的问题是对数。math.log不适用于负数:
>>> math.log(-1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: math domain error(预期结果:(0+3.141592653589793j))
如何计算结果复杂的python中的对数?(最好不用自己实现)
发布于 2013-08-17 02:51:45
数学文档明确表示它不支持复数。如果您想在python中使用这样的库,则应该使用cmath。
表示复杂的数学。
cmath与math具有大多数相同的接口,因此,对于您的示例,您只需执行以下操作:
import cmath
cmath.log(-1)https://stackoverflow.com/questions/18284623
复制相似问题