title: Moving Standard Deviation in Python WITHOUT using built-in functions
body: <p>I am trying to calculate the moving standard deviation array of my dataset. I have my original position and time data and have also found the moving average array of this position data. I have have seen the various built in python functions for calculating rolling mean and standard deviations. I am hesitant to use this because a parameter I must set is the direction of the process window (forward: current time to window length, centered: window length centered about current time, backward: window length to current time). This affects the range of data that I must use at each data point. Below is my code for calculating moving average error.</p>
  <pre><code>def MA(pos, t, processWindow, positionTolerance, calculationDirection, figNum):
      #pos and t are position and time lists, processWindow is given in seconds, but represent 
       the length of the window 
  
      N = len(t)
      windowLength = processWindow*1000 #process window given in seconds---&gt; length becomes 50
      
  
      i = 0
      MA = []
      while i &lt; N:
          if calculationDirection == 'Forward':
             startPos = i
             endPos = int(i+ windowLength)
  
          elif calculationDirection == 'Centered':
             startPos = int(i-windowLength/2)
             endPos = int(i+windowLength/2)
  
          elif calculationDirection == 'Backward':
              startPos = int(i-windowLength)
              endPos = i
              
          window = pos[startPos : endPos]
          window_average = round(sum(window) / windowLength, 4)
          MA.append(window_average)
          
          i+=1
      return MA
  </code></pre>
  <p><code>MA</code> returns a list with the moving average value at each position point. Is there a way to compute the moving standard deviation in a similar manner?</p>