<jupyter_start><jupyter_text>Random walk 1D(Function)<jupyter_code>import numpy as np
import random as random
import matplotlib.pyplot as plt
import seaborn as sns
sns.set()
def walk1D(x,N,d):
    
    '''This function returns the space 'X' and time 'T'
 for random walk in 1D
       x:initial position
       N:total number of steps
       d:step length'''
    
    
    '''X stores 1-D coordinate'''
    X =[]
    
    '''T stores time coordinate'''
    T =[]
    
    
    
    '''iteration N steps'''
    for t in range(N):
        
       '''walk one step ahead'''
       x=x+d*random.choice([-1,1])
        
       '''collect time'''
       T.append(t)
       '''collect position'''
       X.append(x)
        
    return X,T
    
    
'''Implement function to get data'''
X,T = walk1D(x=0,N=1000,d=1)
'''Make a plot'''
plt.figure(figsize =[10,3])
plt.scatter(T,X,marker ='.')
plt.plot(T,X)
plt.xlabel("Time")
plt.ylabel("Displacement")
plt.show()

X1,T1 = walk1D(x=0,N=1000,d=1)
X2,T2 = walk1D(x=0,N=1000,d=1)
X3,T3 = walk1D(x=0,N=1000,d=1)
X4,T4 = walk1D(x=0,N=1000,d=1)
'''Make plots'''
plt.figure(figsize =[10,5])
plt.scatter(T,X,marker ='.')
plt.plot(T1,X1)
plt.plot(T2,X2)
plt.plot(T3,X3)
plt.plot(T4,X4)
plt.xlabel("Time")
plt.ylabel("Displacement")
plt.show()

plt.figure(figsize =[15,8])
for a in range(10):
    X,Y = walk1D(0,1000,1)
    plt.plot(Y,X)

    plt.xlabel("Time")
    plt.ylabel("Displacement")<jupyter_output><empty_output><jupyter_text>Random walk 1D by (class)<jupyter_code>class Walk1D(object):                                  

    ''' This is a class to create on dimentional walk:
      x0 : initial position
      d  : step size 
      N :  number of steps in random walk''' 
    
    def __init__(self,N,d,x0):
        self.N = N
        self.X = []     
        self.d = d
        self.x0 = x0

    def walk1D(self):
        '''note initial position'''
        x = self.x0
        k = 0
        while k < self.N:
            '''Walk one step ahead'''
            x = x + self.d*random.choice([-1,1])
            '''collect position'''
            self.X.append(x)
            
            k = k+1
        return self.X<jupyter_output><empty_output><jupyter_text>generate 5 different walk of steps 1000 each<jupyter_code>import numpy as np
import random as random
import matplotlib.pyplot as plt
%matplotlib inline
import seaborn as sns
sns.set()

X1=Walk1D(N =1000,d=1,x0=0).walk1D()
X2=Walk1D(N =1000,d=1,x0=0).walk1D()
X3=Walk1D(N =1000,d=1,x0=0).walk1D()
X4=Walk1D(N =1000,d=1,x0=0).walk1D()
X5=Walk1D(N =1000,d=1,x0=0).walk1D()
T=[i for i in range(len(X1))]
print(len(X1))
import json
with open ('rwalk5.json', 'w')as f5:
    json.dump([X1,X2,X3,X4,X5,T],f5)
plt.figure(figsize = [10,6])
plt.plot(T,X1)
plt.plot(T,X2)
plt.plot(T,X3)
plt.plot(T,X4)
plt.plot(T,X5)
plt.xlabel("Time")
plt.ylabel('Displacement')
plt.grid(True)
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16993464052287582, 'fraction_numerical': 0.05503955968352253, 'mean_word_length': 2.9033557046979865, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '129696', 'license': 'MIT', 'n_tokens_mistral': 1282, 'n_tokens_neox': 1202, 'n_words': 243, 'path': 'Random walk in 1D.ipynb', 'repo_name': 'Rabibryan/Random-walk', 'size': '2907'}