Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想将Symengine复数转换I为 python 1j,以便我可以在普通 python 中使用这些数字。目前,我有一个代码,但它运行使用sympy它使其变慢。任何替代解决方案或加速此代码?这是我的代码:
Symengine
I
1j
sympy
import sympy from time import time from symengine import * def sym2num(x): return complex(sympy.sympify(x))
这是我从中获取代码的参考
谢谢
SymEngine 中还没有内置的方法可以做到这一点(欢迎 PRs)。
这是一个相当快的解决方法。
def sym2num(x): return float(x.real_part()) + float(x.imaginary_part())*1j