Calculation of a formula with summation term

14 views
Skip to first unread message

gma80

unread,
Dec 1, 2014, 8:43:20 AM12/1/14
to sy...@googlegroups.com
I am a newbie with the sympy library, and I am having trouble to calculate the mean after have defined the formula:

    import sympy as sp
   
import numpy as np
    sp
.init_printing()
   
    mu
, N, i, x_i = sp.symbols( 'mu N i x_i' )
    mu_form
= sp.Eq( mu , (1/N) * sp.Sum( x_i, (i, 1, N) ) )



Now I want to define a list of values for `x_i` to actually calculate the mean.. I have attempted in such a way, but it does not seem to work properly:

    x_i_val = (1, 1, 3, 3, 2, 2, 2, 2)
    mu_val
= mu_form.subs( [(x_i, x_i_val), (N, 8)] )



I am not interested in the `mean` in particular, I want to understand the way to calculate the result of such a formula, with a summation inside.

I did not have luck in finding a minimal example in the available tutorials and Googling.

(Asked on: http://stackoverflow.com/q/27209251/2741329)
Reply all
Reply to author
Forward
0 new messages