1D Random Walk from Matlab to Python
问题 I have a Matlab code that generates a 1D random walk. %% probability to move up or down prob = [0.05, 0.95]; start = 2; %% start with 2 positions(1) = start; for i=2:1000 rr = rand(1); down = rr<prob(1) & positions(i-1)>1; up = rr>prob(2) & positions(i-1)<4; positions(i) = positions(i-1)-down + up; figure(1), clf plot(positions) This gives me the plot below 1D Random Walk with Matlab I need to try to translate this in Python and I have came up with this (using numpy): import random import