import pylab import math # Rolling the die 1000 times v = pylab.randint(1,7,size=(1000)) print 'mean',pylab.mean(v) print 'variance',pylab.var(v) pylab.hist(v, bins=6) # histogram of the outcoming pylab.xlim(1,6) pylab.show()Here's the result:
mean 3.435 variance 2.781775
Just as a tip, it is generally much more efficient to generate large arrays using numpy (and pylab) built-ins. So for example instead of using a for loop to append values, just use `v=pylab.randint(1,7,size=(1000,))`
ReplyDeleteI agree with you, I modified the code. Thanks!
ReplyDeletecan sent me your modified cause this code not operate
Deletenice post!
ReplyDelete