title: Local linear approximation in numpy
body: <p>I have some <code>x</code> and <code>y</code> data, where for every entry in the <code>x</code> vector there's a corresponding entry in the <code>y</code> vector. Furthermore, the <code>x</code> data are not evenly spaced. </p>
  
  <p>I'd like to interpolate between the <code>x</code> samples to obtain an even spacing in the <code>x</code> dimension, and to approximate the corresponding <code>y</code> value. In <strong>numpy</strong>, <code>interp1d</code> seems like a natural solution, but my problem has a caveat: the <code>x</code> values are not monotonically increasing (because both <code>x</code> and <code>y</code> are a function of time). The <code>interp1d</code> function, and the other functions from the interpolate module, thus give weird results at those points where <code>x</code> reverses direction. </p>
  
  <p>What I'd really like to do is simply fit a straight line between every set of two adjacent <code>x</code> points and then interpolate based on this very local approximation. Is there a function to do this in <strong>numpy</strong> or do I have to rig something up myself?</p>