[SciPy-user] Misunderstanding scipy.interpolate.interp2d?

josef.pktd at gmail.com josef.pktd at gmail.com
Mon Jul 6 17:01:51 EDT 2009


On Mon, Jul 6, 2009 at 10:18 AM, Adrian
Price-Whelan<adrian.prw at gmail.com> wrote:
> Hey all --
>
> Perhaps I am misunderstanding the documentation for the function
> scipy.interpolate.interp2d, or maybe I just don't understand the math
> of how it works. If it is a true 2-D interpolating function, why would
> it take 2 1-dimensional arrays as input? For instance, say I had image
> data in a 2-D array that I wanted to shift by some sub-pixel amount,
> like 0.3 pixels, to some arbitrary direction. How would I take an
> array ( something like [[1,2,3],[4,5,6],[7,8,9]] ) and break this into
> 2 1-D arrays x and y to use this function to interpolate new values
> based on the sub-pixel shift?
>
> Thanks!!
> -Adrian

x and y are the coordinates, z are the values.
If I understand your example correctly then something like this should work

import numpy as np
from scipy import interpolate

z = np.array([[1,2,3],[4,5,6],[7,8,9]])
#t,x = np.mgrid[0:3,0:3] #for full grid values
x = np.arange(3)
y = np.arange(3)

ip = interpolate.interp2d(x,y,z)
xn = np.linspace(0,2,7)
yn = np.linspace(0,2,7)
print ip(xn,yn)  # interpolated value with call

Josef



More information about the SciPy-User mailing list