Reputation: 649
This is most likely because I do not know how to use the standard scipy expect function method. When I use:
from scipy.stats import uniform
uniform.expect(lambda k: k**2,lb=-0.2,ub=0.2)
I got value : 0.0026666666666666666
If I use manual calculation:
np.mean(np.random.uniform(-0.2,0.2,1000)**2)
I got 0.013235491320680141, which is the right value I expect. So what did I do wrong with standard expect or integral function? Any help please.
Upvotes: 1
Views: 372
Reputation: 97555
If you look at the documentation for expect
, ub
and lb
do not mean what you think they do. They are bounds on the integral, not parameters for the distribution.
You actually want:
scipy.stats.uniform(loc=-0.2, scale=0.4).expect(lambda x: x**2)
Upvotes: 3