Python3:计算复指数和对数
Python3:计算复指数和对数,python,python-3.x,complex-numbers,Python,Python 3.x,Complex Numbers,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.log不适用于负数: >>> math.log(-1) Traceback (most rec
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.log
不适用于负数:
>>> math.log(-1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: math domain error
>数学日志(-1)
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
ValueError:数学域错误
(预期结果:(0+3.141592653589793j)
)
如何在python中计算结果复杂的对数?
(最好不要自己实现)数学文档明确表示它不支持复数。如果希望python中有一个这样的库,那么应该使用 Cmath代表复杂数学 cmath与math的大部分接口相同,因此对于您的示例,您可以执行以下操作:
import cmath
cmath.log(-1)
伟大的谢谢RTFM为我。我应该读一下文件的第一段。冷静期一结束,我们就会接受。@hyperoreus别担心,这发生在我们中最好的人身上。
import cmath
cmath.log(-1)