title: python numpy - is there a faster way to convolve?
body: <p>I have a numpy array that is very large (1 million integers). I'm using np.convolve  in order to find the "densest" area of that array. By "desnsest" area I mean the window of a fixed length that has the the highest numbers when the window is summed. Let me show you in code:</p>
  
  <pre><code>import numpy as np
  
  example = np.array([0,0,0,1,1,1,1,1,1,1,0,1,1,1,1,0,0,0,1,0,0,1,1,0,1,0,0,0,0,0,1,0])
  window_size = 10
  density = np.convolve(example, np.ones([window_size]), mode='valid')
  print(density) 
  # [7.0, 7.0, 8.0, 9.0, 9.0, 9.0, 8.0, 7.0, 6.0, 6.0, 5.0, 5.0, 5.0, 5.0, 4.0, 4.0, 4.0, 4.0, 4.0, 3.0, 3.0, 4.0, 3.0]
  </code></pre>
  
  <p>I can then use <code>np.argmax(density)</code> to get the starting index of the highest density area <code>3</code>.</p>
  
  <p>Anyway, with this example it runs fast. but when convolving over million element array and with a window size of 10,000 it takes 2 seconds to complete. if I choose a windows_size of 500,000 it takes 3 minutes to complete.</p>
  
  <p>Is there a better way to sum over the array with a certain window size to speed this up? If I converted this into a pandas series instead could I perhaps use something there?</p>
  
  <p>Thanks for your help!</p>