In [7]:
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline

from scipy.interpolate import RegularGridInterpolator

Multilinear Interpolation

  • Use RegularGridInterpolator from scipy.interpolate

Do a 3D example, that is, we have some data $f_i = z_i(x_i, y_i, z_i)$

In [21]:
#-------- define grids in x, y, z

x = np.linspace(0,1,101)
y = np.linspace(0,1,101)
z = np.linspace(0,1,101)

#-------- define the function on the grid

X,Y,Z = np.meshgrid(x,y,z)        # just used for conveninece 
f = np.sin(9*X)*np.sin(9*Y)*Z

#-------- define interpolant and interpolate to "wanted" point xw, yw, zw

finterp = RegularGridInterpolator( (x,y,z), f )

xw = yw = zw = 0.155
f_w = finterp( (xw, yw, zw) )
f_w
Out[21]:
array(0.1499549)
In [ ]:
 
In [ ]: