title: Mean square displacement of a 1d random walk in python
body: <p>I'd like to calculate the mean square displacement at all times of a 1d trajectory. I'm a novice programmer, so I've attempted it from a simulated random walk.</p>
  <pre><code>import numpy as np
  import matplotlib.pyplot as plt
  
  # generate random walk
  path = np.zeros(60)
  position = 0
  for i in range(1, path.size):
      move = np.random.randint(0, 2)
      if move == 0: position += -1
      else: position += 1
      path[i] = position
  
  # returns a vector of MSDs from a given path
  def calcMSD(data):
      msd = np.zeros(data.size - 1)
      for i in range(1, data.size):
          squareddisplacements = (data[i:] - data[:data.size - i])**2
          msd[i - 1] = squareddisplacements.mean()
      return msd
  
  msd = calcMSD(path)
  plt.plot(msd)
  plt.show()
  </code></pre>
  <p>Have I implemented this correctly? Any and all advice is appreciated, thanks.</p>