title: How to make moving window faster?
body: <p>I use a moving window to buffer raster data (numpy array). It is very slow and I am wondering if it is possible to improve the code to make it faster:
  My actual arrays have the shape (1349, 1368) and consist of zeros and ones.</p>
  <pre><code>import numpy as np
  
  clouds = np.array([[[0, 0, 0, 0, 0], 
                      [0, 0, 0, 1, 0],
                      [0, 0, 1, 1, 1],
                      [0, 0, 0, 0, 1],
                      [0, 0, 0, 0, 1],
                      ]])  
  
  cloudShadow = np.array([[[1, 0, 0, 1, 1], 
                           [0, 1, 1, 0, 0],
                           [0, 1, 0, 0, 0],
                           [0, 0, 0, 0, 0],
                           [0, 0, 0, 0, 1],
                           ]])
  
  row_up_cloudShadow = 1      
  row_low_cloudShadow = 0     
  col_left_cloudShadow = 1  
  col_right_cloudShadow = 0 
  
  
  row = []
  for i in range(len(np.where(clouds == 1)[0])):
      row_xy = list(range((np.where(clouds == 1)[0][i] - row_up_cloudShadow), (np.where(clouds == 1)[0][i] + row_low_cloudShadow) +1))
      row.append(row_xy)
  
  
  col = []
  for i in range(len(np.where(clouds == 1)[1])):
      col_xy = list(range((np.where(clouds == 1)[1][i] - col_left_cloudShadow), (np.where(clouds == 1)[1][i] + col_right_cloudShadow) +1))
      col.append(col_xy)
  
  buffer = []
  for i in range(0, np.count_nonzero(clouds == 1)):
      
      for j in range(len(row[0])):
          z = row[i][j]
          
          for u in range(len(col[0])):
              s = col[i][u]
              
              buffer.append(np.array([z,s]))
  
  buffer = np.asarray(buffer)
  buffer = np.where(buffer &lt; 0, 0, buffer)
  
  data_buff_cloudShadow = np.zeros(clouds.shape)
  for i in range(len(buffer)):
      data_buff_cloudShadow[buffer[i][0]][buffer[i][1]] = 1
  
  cloudShadow_buff = np.where(data_buff_cloudShadow == 1, cloudShadow, 0)
  
  </code></pre>