This is probably a really stupid question, but I just can't seem to work out how to do it for some reason. I've created a function for a random walk here which just uses the numpy binomial function with one trial (ie if it's under 0.5 it's -1, over it's +1. However this obviously makes the first value of the function either -1 or +1, whereas I want it to be zero. How can I change this?
import numpy as np
import matplotlib.pyplot as plt
def random_walk(N,d):
walk = d*np.cumsum(2*np.random.binomial(1,.5,N-1)-1)
return walk
plt.plot(np.arange(1,250),random_walk(250,1))
plt.show()
Again, it's probably really simple and I'm being really stupid, but I'd really appreciate the help!