title: Squeezing a numpy array
body: <p>Here is an example of what I intend to do. I have input data, something like this:</p>
  
  <pre><code>data = array([0,1,2,3,4,5,6,7,8,9])
  </code></pre>
  
  <p>What I need to do is to so sum up the first two values, then next two values and so on. So the result should be as following.</p>
  
  <pre><code>result = array([1,5,9,13,17])
  </code></pre>
  
  <p>This is what I am terming as 'squeezing'</p>
  
  <p>I have a numpy array of size 4096. I need to squeeze the array to size of 2048,1024 or 512.
  It is actually energy spectrum where the indices of array give ADC channel no. and the value gives photon counts. 
  To do this, here is what I do. </p>
  
  <pre><code> # tdspec is input array of size 4096
   spec_bin_size = 1024
   spect = n.zeros(spec_bin_size)
   i = 0
   j=0
   interval = 4096/spec_bin_size
   while j &lt; spec_bin_size:
       a = n.sum(tdspec[i:i+interval])
       spect[j] = a
       i = i+interval
       j = j+1
  </code></pre>
  
  <p>It works well, but now I need to run this loop upon a number of spectra and I fear that it will be slow.
  Can anyone please tell me if there is a numpy/scipy operation that does this work?</p>