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)