# [SciPy-user] 2D Interpolation

Ryan May rmay31@gmail....
Fri Jun 27 15:46:30 CDT 2008

```Pauli Virtanen wrote:
> Hi,
>
> Fri, 27 Jun 2008 14:13:22 -0400, Ryan May wrote:
>> 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.
>
> I don't think there are currently any functions that do that, but
> certainly we'd like to have them.
>
> I created a Scipy enhancement ticket for this feature:
>
> 	http://scipy.org/scipy/scipy/ticket/693
>
> Attached to it is a quick patch that implements the necessary loop on the
> Fortran side. I suspect the patch needs further work, as there possibly
> are faster ways to vectorise this piece of computation than simply
> calling fpbisp at each point separately. (If someone more familiar with
> the spline code wants to bless it, I can commit it, though...)
>
> Currently, you can use
>
> 	spl = scipy.interpolate.RectBivariateSpline(xi,yi,zi)
> 	z = scipy.array([spl(xp, yp)[0,0] for xp, yp in zip(x, y)])
>
> The Python overhead isn't as bad as it looks like; moving the loop to
> the Fortran side gains only a factor of 5 improvement in speed.

Thanks for that.  I'm surprised that the Python looping overhead isn't
worse. I just automatically assumed looping of Python == death of my
code.  I'll see what I get then just manually looping.

Thanks

--
Ryan May