title: Extrapolate with LinearNDInterpolator
body: <p>I've got a 3D dataset that I want to interpolate AND extrapolate linearly. The interpolation can be done easily with <a href="http://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.LinearNDInterpolator.html" rel="nofollow noreferrer"><code>scipy.interpolate.LinearNDInterpolator</code></a>. The module can only fill in a constant/nan for values outside the parameter range, but I don't see why it would not offer an option to turn on extrapolation.</p>
  
  <p>Looking at the code, I see that the module is written in cython. With no experience in cython, it is hard to play around with the code to implement extrapolation. I can  write it in pure python code, but maybe someone else here has a better idea? My particular case involves a constant xy-grid, but the z-values keep changing a lot (-100,000) and therefore the interpolation must be fast as the interpolation will be runned for each time the z-values change.</p>
  
  <p>To give a basic example, as requested, lets say that I have a grid like</p>
  
  <pre><code>xyPairs = [[-1.0, 0.0], [-1.0, 4.0],
             [-0.5, 0.0], [-0.5, 4.0],
             [-0.3, 0.0], [-0.3, 4.0],
             [+0.0, 0.0], [+0.0, 4.0],
             [+0.2, 0.0], [+0.2, 4.0]]
  </code></pre>
  
  <p>and lets say I want to calculate values at <code>x = -1.5, -0.8, +0.5</code> and <code>y = -0.2, +0.2, +0.5</code>. Currently, I am performing 1d interpolation/extrapolation along the x-axis for each y-value and then along the y-axis for each x-value. The extrapolation is done by the second function in <a href="https://stackoverflow.com/a/6933490/1199619."><code>ryggyr's answer</code></a>.</p>