Last active
          August 29, 2015 14:17 
        
      - 
      
- 
        Save mFoxRU/b368eb0c24df28a57dd5 to your computer and use it in GitHub Desktop. 
    Modified version of rolling window function from (1) that allows choosing rolling (increment) step. // (1) http://www.rigtorp.se/2011/01/01/rolling-statistics-numpy.html
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | import numpy as np | |
| def rolling_window(a, window, step=1): | |
| n = (a.shape[-1] - window) // step + 1 | |
| shape = a.shape[:-1] + (n, window) | |
| strides = a.strides[:-1] + (a.strides[-1]*step, a.strides[-1]) | |
| return np.lib.stride_tricks.as_strided(a, shape=shape, strides=strides) | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment