I'm simulating a 2-dimensional random walk, with direction 0 < θ < 2π and T=1000 steps. I already have:
a=np.zeros((1000,2), dtype=np.float)
def randwalk(x,y):
theta=2*math.pi*rd.rand() # Theta is a random angle between 0 and 2pi
x+=math.cos(theta); # Since spatial unit = 1
y+=math.sin(theta); # Since spatial unit = 1
return (x,y)
x, y = 0., 0.
for i in range(1000):
x, y = randwalk(x,y)
a[i,:] = x, y
This generates a single walk, and stores all intermediate coordinates in the numpy array a. How can I edit my code to repeat the walk 12 times (using a new random seed every time) and then save each run in a separate text file? Do I need a while loop within my randwalk function?
Guess:
rwalkrepeat = []
for _ in range(12):
a=np.zeros((1000,2), dtype=np.float)
x, y = 0., 0.
for i in range(1000):
x, y = randwalk(x,y)
a[i,:] = x, y
rwalkrepeat.append(a)
print rwalkrepeat