Can I calculate exp (1 + 2j) in python?

Is it possible to calculate exp (1 + 2j) in python?

exp(1+2j) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: can't convert complex to float 
+7
source share
2 answers

You need a complex version of this function:

 cmath.exp(1+2j) 

See http://docs.python.org/library/cmath.html

+19
source

You can import e from the math module for this.

For example:

 >>> from math import e >>> print e ** (1+2j) (-1.1312043837568135+2.4717266720048188j) 
+8
source

All Articles