random walks and more about data vizualization def simdrunk(numtrialsdclasswalklengths)meandistances [cvdistances [for numsteps in walklengthsprint 'starting simulation of'numsteps'stepstrials simwalks(numstepsnumtrialsdclassmean sum(trials)/float(len(trials)meandistances append(meancvdistances append(stddev(trials)/meanreturn (meandistancescvdistancesdef simall(drunkkindswalklengthsnumtrials)stylechoice styleiterator((' -'' :'' ')for dclass in drunkkindscurstyle stylechoice nextstyle(print 'starting simulation of'dclass __name__ meanscvs simdrunk(numtrialsdclasswalklengthscvmean sum(cvs)/float(len(cvs)pylab plot(walklengthsmeanscurstylelabel dclass __name__ '(cv str(round(cvmean )')'pylab title('mean distance from origin (str(numtrialstrials)'pylab xlabel('number of steps'pylab ylabel('distance from origin'pylab legend(loc 'best'pylab semilogx(pylab semilogy(simall((usualdrunkcolddrunkewdrunk)( , , , , ) figure plotting the walks of different drunks the code in figure produces the plot on the right the usual drunk and the phototropic drunk (ewdrunkseem to be moving away from the origin at approximately the same pacebut the heat-seeking drunk (colddrunkseems to be moving away orders of magnitude faster this is interesting given that on average he is only moving faster (he takeson averagefive steps for every four taken by the othersalsothe coefficients of variation show quite spreadbut the plot doesn' shed any light on why let' construct different plotthat may help us get more insight into the behavior of these three classes instead of plotting the change in distance over time for an increasing number of stepsthe code in figure plots the distribution of final locations for single number of steps