简体   繁体   English

将 sympy 方程计算为十进制(在 sympy 中)

[英]Evaluating sympy equation as decimal (inside sympy)

I have a sympy equation that gives me:我有一个 sympy 方程,它给了我:

>>> ans0=solve([c_eq1, c_eq2, v_eq1, v_eq2, v_eq3],[a, b, c, d, e])
>>> ans0
{a: 9/796, b: 27/3980, c: 9/1990, d: 5/796, e: 1/199}

Is there a way to get this answer in decimal without converting it to a float (outside sympy), for example with:有没有办法以十进制形式获得这个答案而不将其转换为浮点数(在 sympy 之外),例如:

dict((var,float(value)) for var, value in ans0.items())
{a: 0.011306532663316583, b: 0.0067839195979899495, c: 0.004522613065326633, d: 0.00628140703517588, e: 0.005025125628140704}

If your question means which sympy function to use instead of float , you can use N如果您的问题意味着使用哪个 sympy 函数而不是float ,您可以使用N

>>> from sympy import N
>>> dict((var, N(value)) for var, value in ans0.items())

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM