title: Python - Average values of numpy multidimensionnal array every specific time
body: <p>I have a multidimensionnal array "test[:,:,:]" and i would like to get averaged values on the test.shape[0] dimension for every 4 "frames" i would like to keep the same dimensions of my array and substitute the 4 values by the mean value.</p>
  
  <p>As example:</p>
  
  <pre><code>test=np.array([[[ 2.,  1.,  1.],
          [ 1.,  1.,  1.]],
  
         [[ 3.,  1.,  1.],
          [ 1.,  1.,  1.]],
  
         [[ 3.,  1.,  1.],
          [ 1.,  1.,  1.]],
  
         [[ 5.,  1.,  1.],
          [ 1.,  1.,  1.]],
  
         [[ 2.,  1.,  1.],
          [ 1.,  1.,  1.]],
  
         [[ 3.,  1.,  1.],
          [ 1.,  1.,  1.]],
  
         [[ 3.,  1.,  1.],
          [ 1.,  1.,  1.]],
  
         [[ 5.,  1.,  1.],
          [ 1.,  1.,  1.]],
  
         [[ 2.,  1.,  1.],
          [ 1.,  1.,  1.]]])        
  
  
  for i in range(test.shape[0]-1,4):
      test_mean = (test[i,:,:]+test[i+1,:,:]+test[i+2,:,:]+test[i+3,:,:])/4.
  </code></pre>
  
  <p>But, i don't keep the same dimension...what is the best way to do that?</p>