更新时间:2023-12-01 08:16:46
所有sympy对象都从sympy.Basic
继承.要以数值方式计算sympy表达式,只需使用.n()
All sympy objects inherit from sympy.Basic
. To evaluate an sympy expression numerically, just use .n()
In [1]: import sympy
In [2]: x = sympy.sqrt(2)
In [3]: x
Out[3]: sqrt(2)
In [4]: x.n()
Out[4]: 1.41421356237310
In [5]: if (isinstance(x, sympy.Basic)):
...: print(x.n())
...:
1.41421356237310