an illustrative application of utilizing array operations is in the simulation of random walks let' first consider simple random walk starting at with steps of and - occurring with equal probability pure python way to implement single random walk with , steps using the built-in random moduleimport random position walk [positionsteps for in xrange(steps)step if random randint( else - position +step walk append(positionsee figure - for an example plot of the first values on one of these random walks figure - simple random walk you might make the observation that walk is simply the cumulative sum of the random steps and could be evaluated as an array expression thusi use the np random module to draw , coin flips at onceset these to and - and compute the cumulative sumin [ ]nsteps in [ ]draws np random randint( size=nstepsin [ ]steps np where(draws - in [ ]walk steps cumsum( numpy basicsarrays and vectorized computation www it-ebooks info