title: non-uniform spacing with numpy.gradient
body: <p>I'm not sure how to specify non-uniform spacing when using numpy.gradient. </p>
  
  <p>Here's some example code for y = x**2.</p>
  
  <pre><code>import numpy as np
  import matplotlib.pyplot as plt
  
  x = [0.0, 2.0, 4.0, 8.0, 16.0]
  y = [0.0, 4.0, 16.0, 64.0, 256.0]
  dydx = [0.0, 4.0, 8.0, 16.0, 32.0] # analytical solution
  
  spacing = [0.0, 2.0, 2.0, 4.0, 8.0] #added a zero at the start to get length matching up with y
  
  m = np.gradient(y, spacing)
  
  plt.plot(x, y, 'bo',
           x, dydx, 'r-', #analytical solution
           x, m, 'ro')    #calculated solution
  plt.show()
  </code></pre>
  
  <p>The length of the spacing array will always be one less than the array I want to calculated the gradient of. Adding in a zero to get the lengths matching up (like in the example code above) gives incorrect answers, with an infinite gradient for one point. </p>
  
  <p>I can't understand / follow the numpy.gradient documentation for non-uniform spacing (<a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.gradient.html" rel="noreferrer">https://docs.scipy.org/doc/numpy/reference/generated/numpy.gradient.html</a>)</p>
  
  <p>How should I specify the spacing between points? Is there an alternative way of doing this?</p>
  
  <p>Numpy version 1.9.2</p>