<jupyter_start><jupyter_text>Random walk (Python) 2D random walk<jupyter_code>import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
from numpy.random import default_rng
rng = default_rng()
# Parameters
N_PARTICLES = 100
N_STEPS = 10000
STEP_SIZE = 1
CHOICES = np.array([[0, 1], [1, 0], [0, -1], [-1, 0]])  # Up, right, down, and left
dx = CHOICES[rng.integers(4, size=(N_STEPS, N_PARTICLES))]
pos = dx.cumsum(axis=0) - dx[0, :, :]
fig, ax = plt.subplots(figsize=(10, 10))
ax.plot(pos[:, 0, 0], pos[:, 0, 1])
ax.plot(pos[:, 1, 0], pos[:, 1, 1])<jupyter_output><empty_output><jupyter_text>**Mean-squared displacement (MSD)**<jupyter_code>fig, ax = plt.subplots(figsize=(10, 10))
msd = np.mean(np.sum(pos**2, axis=1), axis=1)
ax.plot(np.arange(N_STEPS), msd)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.19101123595505617, 'fraction_numerical': 0.049937578027465665, 'mean_word_length': 6.3577981651376145, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '536686', 'license': 'MIT', 'n_tokens_mistral': 382, 'n_tokens_neox': 348, 'n_words': 76, 'path': 'docs/random-walk.ipynb', 'repo_name': 'NTUMitoLab/mmsb-bebi-5009-python', 'size': '801'}