title: Max in a sliding window in NumPy array
body: <p>I want to create an array which holds all the <code>max()</code>es of a window moving through a given numpy array.  I'm sorry if this sounds confusing.  I'll give an example.  Input:</p>
  
  <pre><code>[ 6,4,8,7,1,4,3,5,7,2,4,6,2,1,3,5,6,3,4,7,1,9,4,3,2 ]
  </code></pre>
  
  <p>My output with a window width of 5 shall be this:</p>
  
  <pre><code>[     8,8,8,7,7,7,7,7,7,6,6,6,6,6,6,7,7,9,9,9,9     ]
  </code></pre>
  
  <p>Each number shall be the max of a subarray of width 5 of the input array:</p>
  
  <pre><code>[ 6,4,8,7,1,4,3,5,7,2,4,6,2,1,3,5,6,3,4,7,1,9,4,3,2 ]
    \       /                 \       /
     \     /                   \     /
      \   /                     \   /
       \ /                       \ /
  [     8,8,8,7,7,7,7,7,7,6,6,6,6,6,6,7,7,9,9,9,9     ]
  </code></pre>
  
  <p>I did not find an out-of-the-box function within numpy which would do this (but I would not be surprised if there was one; I'm not always thinking in the terms the numpy developers thought).  I considered creating a shifted 2D-version of my input:</p>
  
  <pre><code>[ [ 6,4,8,7,1,4,3,5,7,8,4,6,2,1,3,5,6,3,4,7,1 ]
    [ 4,8,7,1,4,3,5,7,8,4,6,2,1,3,5,6,3,4,7,1,9 ]
    [ 8,7,1,4,3,5,7,8,4,6,2,1,3,5,6,3,4,7,1,9,4 ]
    [ 7,1,4,3,5,7,8,4,6,2,1,3,5,6,3,4,7,1,9,4,3 ]
    [ 1,4,3,5,7,8,4,6,2,1,3,5,6,3,4,7,1,9,4,3,2 ] ]
  </code></pre>
  
  <p>Then I could apply <code>np.max(input, 0)</code> on this and would get my results.  But this does not seem efficient in my case because both my array and my window width can be large (>1000000 entries and >100000 window width).  The data would be blown up more or less by a factor of the window width.</p>
  
  <p>I also considered using <code>np.convolve()</code> in some fashion but couldn't figure out a way to achieve my goal with it.</p>
  
  <p>Any ideas how to do this efficiently?</p>