【发布时间】:2019-10-06 19:59:51
【问题描述】:
我需要有关 Sympy 的帮助,我实际上有一个多项式列表,比如说 2 个变量 s0 和 s1,但是有些多项式在 s0 中 而已,有的只有 s1,有的只是常数,有的有两个变量,例如:
poly = [1 , s0 , s0+3*s1 , .... ]
我想用相同的命令来评估它们中的任何一个,比如说 s0=2 和 s1=1。例如评估我尝试过的列表的第三个多项式
s = sympy.symbols('s0:%d'2)
poly[2].subs(s,[2,0])
# s is containing (s0, s1), but this won't work at all
poly[2].eval([2,0])
# this one works only if the polynomial uses the two variables, so it will throw an error for poly[0] and poly[1]
事实是我不知道哪个变量有哪个变量,我也不知道先验有多少变量,这最后的信息是函数的输入。因此需要对列表中的所有多项式使用数组和相同的命令。
【问题讨论】:
标签: python-3.x sympy