this is a basic random walk problem.
according to the contents of the book, I try to find indexes on axis=1 whose absolute value is greater than or equal to 7, but there are always several rows whose index is 0, and the index entered normally is fine. I don"t understand the reason for 0. Carefully examined many parts of the program, it is useless.
Source code:
import numpy as np
from numpy import random
nwalks = 10
nsteps = 100
draws = np.random.randint (0,2, (nwalks, nsteps))
steps = np.where (draws > 0,1,-1)
walks = steps.cumsum (1)
hits7 = (np.abs (walks) > 7). Any (1)
print (hits7)
crossing_times = (np.abs (Walks [hits7] > = 7) .argmax (1)
print ((Walks [hits7])
print (crossing_times)
A total of 10 outputs, 8 for true, that is, finding indexes with an absolute value greater than 7 in 8 lines, the case says that there should not be zeros, and rows that are not zero in the result are fine, but why are there zeros? Ask the great god for guidance.