[SciPy-User] Problem with scipy.interpolate.RectBivariateSpline

Peter Baek mr.peter.baek@gmail....
Wed Mar 23 06:10:02 CDT 2011


Hi,

I find it strange that scipy.interpolate.RectBivariateSpline cannot
evaluate a random vector. When i evaluate an ordered vector using e.g.
linspace it works fine, but when i try a random vector it crashes.

Please help me find a way to evaluate an unordered vector.

Thanks,
Peter.

Here is a test bench code that demonstrates the problem:

--------------BEGIN CODE------------------------------------------
from pylab import *
from scipy import interpolate

"""
first create a 2D space to do interpolation within
"""
Nx=11
Ny=6
f=zeros((Ny,Nx))

x=linspace(0,Nx-1,Nx)
y=linspace(0,Ny-1,Ny)
for i in arange(Nx):
   for j in arange(Ny):
       f[j,i]=x[i]+y[j]**2

matx=kron(ones((Ny,1)),x)
maty=kron(ones((1,Nx)),y.reshape(-1,1))
print f
print matx
print maty

figure(1)
c=contour(matx,maty,f)
clabel(c)
title('surface which i want to interpolate in')


"""
Now create an interpolation...
"""

finter_x=interpolate.RectBivariateSpline(y,x,f,kx=3,ky=3)

"""
and evaluate using a linspace vector...
"""

xi1=[5]
yi1=linspace(0,5,100)
print yi1

figure(2)
plot(yi1,finter_x(yi1,xi1))
title('slice at x=5 ordered vector')

"""
and evaluate using a random vector...
"""

xi2=[5]
yi2=rand(100)*5
#yi2=linspace(0,5,100)
print yi2

figure(3)
plot(yi1,finter_x(yi2,xi2))
title('slice at x=5 random vector')
show()

--------------------------- END CODE -----------------------------


More information about the SciPy-User mailing list