title: Rolling window for 1D arrays in Numpy?
body: <p>Is there a way to efficiently implement a rolling window for 1D arrays in Numpy?</p>
  
  <p>For example, I have this pure Python code snippet to calculate the rolling standard deviations for a 1D list, where <code>observations</code> is the 1D list of values, and <code>n</code> is the window length for the standard deviation:</p>
  
  <pre><code>stdev = []
  for i, data in enumerate(observations[n-1:]):
      strip = observations[i:i+n]
      mean = sum(strip) / n
      stdev.append(sqrt(250*sum([(s-mean)**2 for s in strip])/(n-1)))
  </code></pre>
  
  <p>Is there a way to do this completely within Numpy, i.e., without any Python loops? The standard deviation is trivial with <code>numpy.std</code>, but the rolling window part completely stumps me.</p>
  
  <p>I found <a href="http://www.rigtorp.se/2011/01/01/rolling-statistics-numpy.html" rel="noreferrer">this</a> blog post regarding a rolling window in Numpy, but it doesn't seem to be for 1D arrays. </p>