title: How to resize N-d numpy image?
body: <p>How to resize N-d numpy image?</p>
  
  <p>I don't just want to subsample it, but to interpolate / average the pixels.</p>
  
  <p>For example, if I start with</p>
  
  <pre><code>array([[[3, 1, 3, 1],
          [3, 1, 3, 1],
          [3, 1, 3, 1],
          [3, 1, 3, 1]],
  
         [[3, 1, 3, 1],
          [3, 1, 3, 1],
          [3, 1, 3, 1],
          [3, 1, 3, 1]]], dtype=uint8)
  </code></pre>
  
  <p>and shrink it by a factor of 2 in all dimensions, I want the output to be</p>
  
  <pre><code>array([[[2, 2],
          [2, 2]]], dtype=uint8)
  </code></pre>
  
  <p><strong>Attempted solutions:</strong></p>
  
  <p>A. SciPy ndimage:</p>
  
  <pre><code>&gt;&gt;&gt; scipy.ndimage.interpolation.zoom(x, .5, mode='nearest')
  
  array([[[3, 1],
          [3, 1]]], dtype=uint8)
  </code></pre>
  
  <p>(The optional <code>order</code> parameter makes no difference)</p>
  
  <p>B. Looping over <code>2**3</code> possible offsets: ugly, slow, works only for integer zoom factors, and needs extra steps to avoid overflows.</p>
  
  <p>C. OpenCV and PIL work only with 2D images.</p>