I got a sympy array
sympyarray = Matrix([[2/(dx**2*(exp(I*theta) + 1)), -2*exp(-I*theta)/dx**2, 2*exp(-I*theta)/(dx**2*(exp(I*theta) + 1))]])
and want to transform it into a numpy array
numpyarray=np.array([2/(dx**2*(np.exp(1j*theta) + 1)), -2*np.exp(-1j*theta)/dx**2, 2*np.exp(-1j*theta)/(dx**2*(np.exp(1j*theta) + 1))])
and wonder if there are any good way to do this?
My method has until now been the following:
- convert the complex " I " in sympyarray to "1j" using sympy.subs
convert the sympy array into numpy array using
numpyarray = sympyarray.tolist()
- inserting "np." before all the exp(1j*theta) in the printed numpyarray, since the .tolist() dont change the sympy exponential into a numpy exponential.
It surely must be an easier way?
Note: To my knowlage, lambdify is not the answer here. As I read the documentation, lambdify converts a sympy expression into a function that need numerical input? Or am I way off?
thetaanddxto have a numericalnumpyarray, or to keep it as a function that returns an ndarray?thetaanddxin the array, but i need them to be dynamic to be able to change the dx and theta value. Or was that an answer to your question?