I want to convert Symengine
complex number I
to python 1j
so that I can use these numbers in normal python. Currently, I have a code but it runs using sympy
which makes it slower. Any alternative solution for this or speed up this code?. Here is the code I have:
import sympy
from time import time
from symengine import *
def sym2num(x):
return complex(sympy.sympify(x))
Here is the reference from which I took the code
Thank you
There's no built-in way to do this in SymEngine yet (PRs are welcome).
Here's a workaround that is reasonably fast.
def sym2num(x):
return float(x.real_part()) + float(x.imaginary_part())*1j