title: slicing numpy array along an arbitrary dimension
body: <p>say that I have a (40,20,30) numpy array and that I have a function that after some work will return half of the input array along a selected input axis. Is there an automatic way to do so ? I would like to avoid such an ugly code:  </p>
  
  <pre><code>def my_function(array,axis=0):
  
      ...
  
      if axis == 0:
          return array[:array.shape[0]/2,:,:] --&gt; (20,20,30) array
      elif axis = 1:
          return array[:,:array.shape[1]/2,:] --&gt; (40,10,30) array
      elif axis = 2: 
          return array[:,:,:array.shape[2]/2] --&gt; (40,20,15) array
  </code></pre>
  
  <p>thanks for your help</p>
  
  <p>Eric</p>