title: Subsample 1-D array using 2-D indices in numpy
body: <p><strong>Background:</strong>
  The data I'm using is being extracted from a <code>netCDF4</code> object, which creates a numpy masked array at initialization, but does not appear to support the numpy <code>reshape()</code> method, making it only possible to reshape after all the data has been copied = way too slow.</p>
  
  <p><strong>Question:</strong> How can I sub-sample a 1-D array, that is basically a flattened 2-D array, without reshaping it? </p>
  
  <pre><code>import numpy
  
  a1 = np.array([[1,2,3,4],
                 [11,22,33,44],
                 [111,222,333,444],
                 [1111,2222,3333,4444],
                 [11111,22222,33333,44444]])
  
  a2 = np.ravel(a1)
  
  rows, cols = a1.shape
  
  row1 = 1
  row2 = 3
  
  col1 = 1
  col2 = 3
  </code></pre>
  
  <p>I would like to use a fast slicing method that doesn't require reshaping the 1-D array to a 2-D array.</p>
  
  <p><strong>Desired Output:</strong></p>
  
  <pre><code>np.ravel(a1[row1:row2, col1:col2])
  
  &gt;&gt; array([ 22,  33, 222, 333])
  </code></pre>
  
  <p>I got as far as getting the start and ending positions, but this just selects ALL data between these points (i.e. extra columns).</p>
  
  <pre><code>idx_start = (row1 * cols) + col1
  idx_end   = (row2 * cols) + col2
  </code></pre>
  
  <p><strong>Update:</strong>
  I just tried <a href="https://stackoverflow.com/a/16240395/943773">Jaime's brilliant answer</a>, but it appears that <code>netCDF4</code> won't allow for 2-D indices.</p>
  
  <pre><code>z = dataset.variables["z"][idx]
    File "netCDF4.pyx", line 2613, in netCDF4.Variable.__getitem__ (netCDF4.c:29583)
    File "/usr/local/lib/python2.7/dist-packages/netCDF4_utils.py", line 141, in _StartCountStride
      raise IndexError("Index cannot be multidimensional.")
  IndexError: Index cannot be multidimensional.
  </code></pre>