无法将复数转换为浮点数

时间:2018-09-30 17:49:23

标签: python

此代码出现错误,我尝试了很多事情,但仍然会说:

  

回溯(最近一次通话最近):   文件,第7行   TypeError:无法将复数转换为浮点数

这是代码:

Set-Content *.txt

1 个答案:

答案 0 :(得分:1)

math.exp()不支持复杂的参数。您要cmath.exp()

>>> math.exp(1j)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: can't convert complex to float
>>> cmath.exp(1j)
(0.5403023058681398+0.8414709848078965j)

请参见cmath — Mathematical functions for complex numbers