slightly tricky because not all , of them reach we can check this using the any methodin [ ]hits (np abs(walks> any( in [ ]hits out[ ]array([falsetruefalsefalsetruefalse]dtype=boolin [ ]hits sum(number that hit or - out[ ] we can use this boolean array to select out the rows of walks that actually cross the absolute level and call argmax across axis to get the crossing timesin [ ]crossing_times (np abs(walks[hits ]> argmax( in [ ]crossing_times mean(out[ ] feel free to experiment with other distributions for the steps other than equal sized coin flips you need only use different random number generation functionlike normal to generate normally distributed steps with some mean and standard deviationin [ ]steps np random normal(loc= scale= size=(nwalksnsteps) numpy basicsarrays and vectorized computation www it-ebooks info