本文整理汇总了Python中sympy.Poly.as_dict方法的典型用法代码示例。如果您正苦于以下问题:Python Poly.as_dict方法的具体用法?Python Poly.as_dict怎么用?Python Poly.as_dict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sympy.Poly
的用法示例。
在下文中一共展示了Poly.as_dict方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: LM
# 需要导入模块: from sympy import Poly [as 别名]
# 或者: from sympy.Poly import as_dict [as 别名]
def LM(self,poly):
from sympy import S,Poly
if poly==0:return poly
poly = Poly(poly,self.variables)
polyDict = poly.as_dict()
exponents = polyDict.keys()
largest = exponents[0]
for i in xrange(len(polyDict)):
if self.compare(exponents[i],largest): largest = exponents[i]
return Poly({largest:S(1)},self.variables)
示例2: test_poly_internals
# 需要导入模块: from sympy import Poly [as 别名]
# 或者: from sympy.Poly import as_dict [as 别名]
def test_poly_internals():
p = Poly(x**2*y*z + x*y*z**3 + x*y + y*z, x, y, z)
assert p.as_dict() == \
{(1, 1, 3): 1, (1, 1, 0): 1, (2, 1, 1): 1, (0, 1, 1): 1}
assert Poly._permute(p, x) == \
{(2,): y*z, (0,): y*z, (1,): y + y*z**3}
assert Poly._permute(p, y) == \
{(1,): x + z + x*z**3 + z*x**2}
assert Poly._permute(p, z) == \
{(0,): x*y, (3,): x*y, (1,): y + y*x**2}
assert Poly._permute(p, x, y) == \
{(0, 1): z, (1, 1): 1 + z**3, (2, 1): z}
assert Poly._permute(p, y, x) == \
{(1, 2): z, (1, 0): z, (1, 1): 1 + z**3}
assert Poly._permute(p, x, z) == \
{(0, 1): y, (1, 0): y, (1, 3): y, (2, 1): y}
assert Poly._permute(p, z, x) == \
{(1, 2): y, (0, 1): y, (1, 0): y, (3, 1): y}
assert Poly._permute(p, y, z) == \
{(1, 0): x, (1, 3): x, (1, 1): 1 + x**2}
assert Poly._permute(p, z, y) == \
{(0, 1): x, (3, 1): x, (1, 1): 1 + x**2}
q = Poly(x**2*y*z + 2*x*y*z**3 + 3*x*y + 4*y*z, x, y, z)
assert q.as_dict() == \
{(1, 1, 3): 2, (1, 1, 0): 3, (2, 1, 1): 1, (0, 1, 1): 4}
assert Poly._permute(q, z, y, x) == \
{(0, 1, 1): 3, (1, 1, 0): 4, (3, 1, 1): 2, (1, 1, 2): 1}
示例3: new_poly
# 需要导入模块: from sympy import Poly [as 别名]
# 或者: from sympy.Poly import as_dict [as 别名]
def new_poly(V_s, fields, n_coeffs):
"""Make a new polynomial function that has the same powers as V_s function
but with coefficients C1, C2..."""
from sympy import Poly
from sympy import diff, Symbol, var, simplify, sympify, S
from sympy.core.sympify import SympifyError
P = Poly(V_s,*fields)
d = P.as_dict()
e = {}
for key in d.iterkeys():
#print d[key], str(d[key])
for i in xrange(1, n_coeffs+1):
if 'C' + str(i) in str(d[key]):
e[key] = sympify('C'+str(i))
P2 = Poly(e,*fields)
return str(P2.as_basic())