title: Python 2.7: looping over 1D fibers in a multidimensional Numpy array
body: <p>I am looking for a way to loop over <code>1D</code> fibers (row, column, and multi-dimensional equivalents) along any dimension in a 3+-dimensional array. </p>
  
  <p>In a <code>2D</code> array this is fairly trivial since the fibers are rows and columns, so just saying <code>for row in A</code> gets the job done. But for <code>3D</code> arrays for example, this expression iterates over <code>2D</code> slices, not <code>1D</code> fibers.</p>
  
  <p>A working solution is the one below:</p>
  
  <pre><code>import numpy as np
  A = np.arange(27).reshape((3,3,3))
  func = np.sum
  for fiber_index in np.ndindex(A.shape[:-1]):
      print func(A[fiber_index])
  </code></pre>
  
  <p>However, I am wondering whether there is something that is:</p>
  
  <ol>
  <li>More idiomatic </li>
  <li>Faster</li>
  </ol>
  
  <p>Hope you can help!</p>