2 ms·
Matlab: exp(-i*pi*[0 0.5 1]) Python: import cmath import numpy as np np.exp(-1j*cmath.pi*np.array([0, 0.5, 1])) Note that you can't use math
by sampo 8y ago
Matlab:
exp(-i*pi*[0 0.5 1])
Python:
import cmath
import numpy as np
np.exp(-1j*cmath.pi*np.array([0, 0.5, 1]))
Note that you can't use math.exp for complex numbers, and neither math.exp nor cmath.exp works for arrays, you need the separate np.exp. Also, while np.exp actually works on lists, the multiplication doesn't, so you need to keep in mind which variables are python lists (that you mostly cannot do arithmetic on) and which are numpy arrays.
When you are experienced in Python, you know these differences by heart. But if you are a domain specialist and want to test an idea quickly, you will see lots of TypeError messages from Python, you need to google manuals to sort it out, and it will slow you down 10x.
- kryptk 8y agoNone of what you said is wrong, but: 1) there is no need to import anything but numpy to get at pi or e (see constant section of numpy docs). 2) if you wrap all your things you expect to behave like vectors/matrices with np.array() and only use np methods to operate on them you will suffer from shape mismatches instead of TypeErrors, a slightly better fate.