# test_rand.py just plot distributions import numpy import pylab import math from numpy.matlib import rand from random import gauss print "test_rand.py " n=1000000 # one million samples plotn=100 a=rand(n) print "a=",a y=[0 for i in range(plotn)] x=[i/100.0 for i in range(plotn)] for i in range(n): k=int(math.floor(a[0,i]*plotn)) y[k] += 1 y[plotn-1]=n/plotn # should be average print "generating plot test_rand_py.png" pylab.plot(x, y) pylab.xlabel("bin") pylab.ylabel("hits") pylab.grid(True) pylab.title("hits per bin, distribution of rand("+str(n)+")") pylab.savefig("test_rand_py") # writes .png pylab.show() ag=[0.0 for i in range(n)] for i in range(n): ag[i]=gauss(0.0,3.0) # mean,stddev print "ag=",ag[0],ag[1],ag[2],ag[3],ag[4] y=[0 for i in range(plotn)] x=[20.0*i/100.0 for i in range(-plotn/2,plotn/2)] print "len(x)=", len(x) print "len(y)=", len(y) for i in range(n): k=int(math.floor((ag[i]+10.0)*plotn/20.0)) if(k<0): k=0 if(k>=plotn): k=plotn-1 y[k] += 1 print "generating plot test_gauss_py.png" pylab.plot(x, y) pylab.xlabel("bin") pylab.ylabel("hits") pylab.grid(True) pylab.title("hits per bin, distribution of gauss(0.0,3.0)") pylab.savefig("test_gauss_py") # writes .png pylab.show()