0

I seem to get different answers while using scipy interp2d function and LinearNDInterpolator function. I don't understand why. When I calculate it manually, the interpolation using interp2d function seems to be correct. I am calculating for point [0.7,25]

Please help with clarification, the code is below

# -*- coding: utf-8 -*-
"""
Created on Tue May 23 11:03:14 2023

@author: manuelma
"""
from scipy.interpolate import interp2d
from scipy.interpolate import LinearNDInterpolator
### a is a list with x,y values
a=[[0.6, 20], [0.6, 30], [0.8, 20], [0.8, 30]]
### b is a list with z values
b=[1.71, 1.43, 1.57, 1.44]

target_2dinterp=interp2d(list(i[0] for i in a), list(i[1] for i in a), b, kind='linear')
target_lndinterp=LinearNDInterpolator(a,b)

b1=target_2dinterp(0.7,25)
b2=target_lndinterp([0.7,25])
  • how much is the difference? – Learning is a mess May 23 '23 at 10:45
  • @Learningisamess , correct value is 1.5375, interp2d gives an output 1.5375 and linearNDInterpolator gives 1.575. difference is 0.0375 – manuel martin May 23 '23 at 10:50
  • The magnitude of your input data and its mesh should not cause numerical instabilities, I suspect each method uses slightly different maths under the hood. Sorry I cannot help more =) – Learning is a mess May 23 '23 at 10:59
  • Does this answer your question? [scipy.interpolate.LinearNDInterpolator not producing desired functionality](https://stackoverflow.com/questions/12632683/scipy-interpolate-linearndinterpolator-not-producing-desired-functionality) – jared Jun 12 '23 at 17:08
  • Also, as per the scipy documentation on [`interp2d`](https://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.interp2d.html): `Deprecated since version 1.10.0: interp2d is deprecated in SciPy 1.10 and will be removed in SciPy 1.12.0.` – jared Jun 12 '23 at 17:10

0 Answers0