<jupyter_start><jupyter_text>Random walk in 2-D :¶We start at origin (x=0,y=0) and take random steps in each direction giving us 9 possible directions for movement at each step (∆x, ∆y ) ⋲ {-1, 0, 1} : (-1,-1), (-1,0), (-1,1), (0,-1), (0,0), (0,1), (1,-1), (1,0), (1,1) A simulation over 100k steps gives us the following path. A particle moving on the surface of a fluid exhibits 2D random walk and shows a trajectory like below.<jupyter_code>import numpy as np
from itertools import cycle
import matplotlib.pyplot as plt
import random as random
from mpl_toolkits.mplot3d import Axes3D
%matplotlib inline

# Define parameters for the walk
dims = 2
step_n = 100800
step_set = [-1, 0, 1]
origin = np.zeros((1,dims))

# Simulate steps in 2D
step_shape = (step_n,dims)
steps = np.random.choice(a=step_set, size=step_shape)
path = np.concatenate([origin, steps]).cumsum(0)
start = path[:1]
stop = path[-1:]

# Plot the path
fig = plt.figure(figsize=(6,4),dpi=200)
ax = fig.add_subplot(111)
ax.scatter(path[:,0], path[:,1],c='green',alpha=0.25,s=0.05);
ax.plot(path[:,0], path[:,1],c='red',alpha=0.5,lw=0.25,ls='-');
ax.plot(start[:,0], start[:,1],c='black', marker='+')
ax.plot(stop[:,0], stop[:,1],c='blue', marker='o')
plt.title('Two Dimensional Random Walk')
plt.tight_layout(pad=0)
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1838124054462935, 'fraction_numerical': 0.05597579425113464, 'mean_word_length': 5.715736040609137, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '297423', 'license': 'MIT', 'n_tokens_mistral': 540, 'n_tokens_neox': 520, 'n_words': 145, 'path': '2D Random Walk.ipynb', 'repo_name': 'Daya-Ram/Random-Walk', 'size': '1322'}