带有索引变量的 Sympy 求和 [英] Sympy summation with indexed variable
本文介绍了带有索引变量的 Sympy 求和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试使用带有索引变量的 Sum 创建一个 sympy 表达式,如前所述 这里但是,我不能对这个表达式进行lambdify 并给出一个数组来计算总和.这不可能吗?
I try to create a sympy expression with a Sum with an indexed variable as previous explain here However, I can not do lambdify of this expression and give an array to get the sum calculated. Is this impossible?
推荐答案
大概是这样的?
>>> s=Sum(Indexed('x',i),(i,1,3))
>>> f = lambda x: Subs(s.doit(), [s.function.subs(s.variables[0], j)
... for j in range(s.limits[0][1], s.limits[0][2] + 1)], x).doit()
>>> f((30,10,2))
42
这篇关于带有索引变量的 Sympy 求和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文