the walk' trajectoryin [ ]walk min(out[ ]- in [ ]walk max(out[ ] more complicated statistic is the first crossing timethe step at which the random walk reaches particular value here we might want to know how long it took the random walk to get at least steps away from the origin in either direction np abs(walk> gives us boolean array indicating where the walk has reached or exceeded but we want the index of the first or - turns out this can be computed using argmaxwhich returns the first index of the maximum value in the boolean array (true is the maximum value)in [ ](np abs(walk> argmax(out[ ] note that using argmax here is not always efficient because it always makes full scan of the array in this special case once true is observed we know it to be the maximum value simulating many random walks at once if your goal was to simulate many random walkssay , of themyou can generate all of the random walks with minor modifications to the above code the numpy ran dom functions if passed -tuple will generate array of drawsand we can compute the cumulative sum across the rows to compute all , random walks in one shotin [ ]nwalks in [ ]nsteps in [ ]draws np random randint( size=(nwalksnsteps) or in [ ]steps np where(draws - in [ ]walks steps cumsum( in [ ]walks out[ ]array([ - - - - ] ] ] ] ]- - - - ]]nowwe can compute the maximum and minimum values obtained over all of the walksin [ ]walks max(out[ ] in [ ]walks min(out[ ]- examplerandom walks www it-ebooks info