Sympy summation with indexed variable

后端 未结 2 525
情话喂你
情话喂你 2021-01-18 06:25

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 th

2条回答
  •  醉梦人生
    2021-01-18 06:50

    You can use lambdify. Just make sure the limits of the sum match the iterables of a numpy array.

    from sympy import Sum, symbols, Indexed, lambdify
    import numpy as np
    
    x, i = symbols("x i")
    s = Sum(Indexed('x',i),(i,0,3))
    f = lambdify(x, s)
    b = np.array([1, 2, 3, 4])
    f(b)
    

提交回复
热议问题