I am not getting the desired 2D linear interpolation functionality with LinearNDInterpolator. The following piece of code is trying to do an interpolation between the 4 knot points (0,0), (1,0), (0,1), (1,1). interp2d gives me the expected (linear-interpolated) result but LinearNDInterpolator is doing something else, which I am unable to figure out. Perhaps I am not using the API correctly. Unfortunately, I can’t find detailed docs on the usage. Can someone please help or point me to the right forum (mathoverflow ?) to write to ?
>>> f = interp2d([0,1,0,1], [0,0,1,1], [0,1,2,4])
>>> f(0.5,0.5)
array([ 1.75])
>>> g = LinearNDInterpolator([[0,0],[1,0],[0,1],[1,1]], [0,1,2,4])
>>> g(0.5,0.5)
array(2.0)
From http://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.LinearNDInterpolator.html:
In your case, the triangles chosen appear to share the
(0,0), (1,1)edge. Since(0.5, 0.5)is midway between(0,0)and(1,1), the interpolated value lies between the values at those vertices, so it is(0+4)/2 = 2.0.