title: for loop is faster than numpy average, also a bit different result
body: <p>I'm calculating the average slope between a part of a series and a lagged part of the series:</p>
  
  <p>one way is:</p>
  
  <pre><code>def get_trend(series, slen)
      sum = 0.0
      for i in range(slen):
          sum += series[i+slen] - series[i]
      return sum / slen**2 
  </code></pre>
  
  <p>second way is:</p>
  
  <pre><code>numpy.average(numpy.subtract(series[slen:2*slen], series[:slen]))/float(slen)
  </code></pre>
  
  <p>The first code is faster than the second by about 50% according to timeit, and the results differ in the 18th digit and onward for a series of size 200 with slen = 66 and numbers in the series ranging between 0 and 1. </p>
  
  <p>I've also tried to replace the average with sum and divide by slen**2, like I do in the for sum:</p>
  
  <pre><code>numpy.sum(numpy.subtract(series[slen:2*slen], series[:slen]))/float(slen**2)
  </code></pre>
  
  <p>This is equivalent in execution time to the for loop version, but the result is still not exactly the same, it's also (sometime) not the same as the average version, although more often than not it is the same as the average version. </p>
  
  <p>Questions are: 
  Which of these should give the most accurate answer?
  Why does the last version give a different answer from the for loop?
  And why is the average function so inefficient?</p>
  
  <p>Note: for timing I'm measuring the operation on a standard list, on a numpy array the average is faster than the for loop, but the sum is still more than twice as fast as the average.</p>