You are viewing a single comment's thread from:
RE: Random Walk Plots In Python
I have removed the first image. The other images were generated in Python.
From here:
### Multiple Random Walks
nwalks = 200
nsteps = 100
draws = np.random.randint(0, 2, size=(nwalks, nsteps)) # 0 or 1
steps = np.where(draws == 1, 1, -1)
walks = steps.cumsum(1)
I randomly generate 0s and 1s with numpy's random.randint. Any ones stay a one which represent up jumps in the random walk. Anything other than a 1 in numpy's where function (i.e 0) turns into a -1 for a down jump. The where() function is like an if-else statement.