title: Interval average of 1D data
body: <p>I have two 1D arrays, one for measured data and the other one for location. For example, the measured data could be temperature and the other array the heights of the measurement:</p>
  
  <pre><code>temp = np.asarray([10, 9.6, 9.3, ..., -20.3, -21.0])  # Temperature in celsius
  height = np.asarray([129, 145, 167, ..., 5043, 5112]) # Height in meters
  </code></pre>
  
  <p>As you can see, the height of the measurements is not regularly spaced.</p>
  
  <p>I want to compute the mean temperature in regularly spaced height intervals. This is some kind of moving average, but the window size is variable, because the data points inside the interval of interest is not always the same.</p>
  
  <p>This could be done with a for loop in the following way:</p>
  
  <pre><code>regular_heights = np.arange(0, 6000, 100) # Regular heights every 100m
  regular_temps = []
  
  for i in range(len(regular_heights)-1):
      mask = np.logical_and(height &gt; regular_heights[i], height &lt; regular_heights[i+1])
      mean = np.mean(temp[mask])
      regular_temps.append(mean)
  
  regular_temps = np.hstack((regular_temps))
  </code></pre>
  
  <p>I don't like this approach that much and I was wondering if there would be a more "numpy-style" solution.</p>