If i had to create a program where a particle will execute a random walk for N=1000 and must calculate the number of grid positions where the particle visited at least one time.And if i wanted to make 10000 runs and find 10 points (one for every 100 steps ,from 0 to 1000) , which will be the means of 10000 runs

I am doing this:

import scipy as sc import matplotlib.pyplot as plt import random plegma=1000 grid=sc.ones(plegma) # grid full of available positions(ones) for p in range(10000): #-------------------Initialize problem------------------------------------------------- his_pos=[] # list which holds the position of the particle in the grid in_pos = int(sc.random.randint(0,len(grid),1)) #initial position of particle means=[] #list which holds the means #-------------------------------------------------------------------------------------- for i in range(0,1000,100): step=2*sc.random.random_integers(0,1)-1 #the step of the particle can be -1 or 1 # Check position for edges and fix if required # Move by step in_pos += step #Correct according to periodic boundaries in_pos = in_pos % len(grid) #Keep track of random walk his_pos.append(in_pos) history=sc.array(his_pos) mean_his=sc.mean(history) means.append(mean_his) plt.plot(means,'bo') plt.show()

I have these problems :

1) The 10000 runs is the accuracy we want,right?But ,for example, from my code i have this:

('his_pos=', [243]) ('history=', array([243])) ('mean_his=', 243.0) ('means=', [243.0]) ('his_pos=', [243, 244]) ('history=',array([243, 244])) ('mean_his=', 243.5) ('means=', [243.0, 243.5]) ('his_pos=', [243, 244, 243]) ('history=', array([243, 244, 243])) ('mean_his=', 243.33333333333334) ('means=', [243.0, 243.5,243.33333333333334])

and this goes on all over again from the beginning 10000 times. But ,like this ,the information gets lost!(am i right?).But if i put out of the loops the “mean=[]”,then this will keep 10000 values,but i want only 10!I am a bit confused!

Anyway,my plot is not the desired curve ,so somewhere i am making a mistake.

I'll be grateful if someone explains me some things.

Thanks!

(It's a double post but i can't figure the solution..)