def expect_mc(dist, func=(lambda x: 1), size=50000):
 def fun(x):
  return func(x)
 rvs = dist.rvs(size=size)
 return fun(rvs).mean(0)

def expect_mc ( dist , func = ( lambda x : 1 ) , size = 50000 ) : def fun ( x ) : return func ( x ) rvs = dist . rvs ( size = size ) return fun ( rvs ) . mean ( 0 )
calculate expected value of function by monte carlo integration parameters dist : distribution instance needs to have rvs defined as a method for drawing random numbers func : callable function for which expectation is calculated .