[SciPy-user] interp1d question

Touma Jimmy E CTR USAF AFRL/MNGG jimmy.touma.ctr at eglin.af.mil
Wed Oct 18 16:26:40 CDT 2006


Hi all,


I am trying to interpolate in 1d along a columns as opposed to rows 
and it doesn't seem to work. The code below emulates reading data
where interpolation should be done column wise. The error when 
running this code follows. If you could please tell me what I am doing
wrong and how to interpolate along columns.

Thanks,
Jimmy






Here is my code:

#################################################################
import scipy
import numpy

x    = numpy.arange(0,10)
xnew = numpy.arange(0, 9, 0.5)
x    = x.reshape(len(x),1)
xnew = xnew.reshape(len(xnew),1)

y = scipy.exp(-x/3.0)
z = scipy.exp(-x/2.0)
v = scipy.exp(-x)



y = numpy.asanyarray(y)
z = numpy.asanyarray(z)
v = numpy.asanyarray(v)

y=y.reshape(len(y),1)
z=z.reshape(len(z),1)
v=v.reshape(len(v),1)

u = numpy.hstack((y,z,v))


f=scipy.interpolate.interp1d(x,u,kind='linear', axis=0)
##############################################################

I get the following error when I run it:
---------------------------------------------------------------------------
exceptions.ValueError                                Traceback (most recent
call last)

/home/touma/d1.py
     24
     25
---> 26 f=scipy.interpolate.interp1d(x,u,kind='linear', axis=0)
     27
     28

/usr/lib/python2.4/site-packages/scipy/interpolate/interpolate.py in
__init__(self, x, y, kind, axis, copy, bounds_error, fill_value)
    143         len_x,len_y = shape(oriented_x)[interp_axis],
shape(oriented_y)[interp_axis]
    144         if len_x != len_y:
--> 145             raise ValueError, "x and y arrays must be equal in
length along "\
    146                               "interpolation axis."
    147         if len_x < 2 or len_y < 2:

ValueError: x and y arrays must be equal in length along interpolation axis.
WARNING: Failure executing file: <d1.py>

In [3]: numpy.__version__
Out[3]: '1.0b5'

In [4]: scipy.__version__
Out[4]: '0.3.2'




-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/scipy-user/attachments/20061018/2320c153/attachment.html 


More information about the SciPy-user mailing list