[SciPy-user] 2D Interpolation

John Travers jtravs@gmail....
Fri Jun 27 13:37:47 CDT 2008

On Fri, Jun 27, 2008 at 7:13 PM, Ryan May <rmay31@gmail.com> wrote:
> Hi,
> Can anyone help me use scipy.interpolate correctly.  Here's my problem:
> I'm trying to make a 2D lookup table to save some calculations.  The two
> parameters over which the lookup table is generated are independent and
> I have complete control over how I divide up the domain.  Using this
> lookup table, I'd like to then calculate values over an unstructured set
> of parameter values (ie. a list of pairs of parameter values).  Is there
> a function in scipy.interpolate that can help here? What I'd really like
> to be able to do is generate an interpolator object from my 2D array,
> and then pass a pair of 1D arrays to the object and have it return 1D
> array of values.

This should get you started:

import scipy
import scipy.interpolate

# the two axes
x = scipy.linspace(-1.0,1.0,10)
y = x

# make some pretend data
gridy, gridx = scipy.meshgrid(x,y)
z = scipy.sin(gridx)*scipy.sin(gridy)

# create a spline interpolator
spl = scipy.interpolate.RectBivariateSpline(x,y,z)

# make some new axes to interpolate to
nx = scipy.linspace(-1.0,1.0,100)
ny = nx

# evaluate
nz = spl(nx, ny)

# with matplotlib, compare:
import pylab


More information about the SciPy-user mailing list