random_walk 1¶

Query¶

import numpy as np

def random_walk(N):
    """
    This function returns the trajectory of an N step random walk on a one dimensional lattice
    """
    a = 1 # lattice spacing
    x0 = 0
    [insert]
    return traj

Output¶

import numpy as np

def random_walk(N):
    """
    This function returns the trajectory of an N step random walk on a one dimensional lattice
    """
    a = 1 # lattice spacing
    x0 = 0
    traj = np.zeros(N)
    for i in range(N):
        traj[i] = x0
        x0 += a*np.random.choice([-1,1])
    return traj

Evaluate¶

Go to Google Form