Random walk question ask why the argmax output will be a lot of 0? It didn't live up to expectations.

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.

hit7

8true4

8true4

00

Mar.02,2021

when all values in a row are not greater than 7, walks [hits7] > = 7 returns all False on that line.
for the np.argmax function, when all values are the same, the first is returned by default, which is the reason for the occurrence of 0 .

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b362d5-2bfe5.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b362d5-2bfe5.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?