# [SciPy-user] splrep/splev versus interp1d

Stéfan van der Walt stefan@sun.ac...
Wed May 21 06:53:29 CDT 2008

```Hi Johann

If I interpolate on points including the originals, i.e.

x2 = sp.linspace(0,10,200,endpoint=False)

then I see that, for both methods, they at least go through those points:

n [147]: for nr,i in enumerate(x):
print y[nr] - y2[x2 == i]
.....:
.....:
[  3.01232352e-18]
[ -1.11022302e-16]
[ -1.11022302e-16]
[  2.77555756e-17]
[ 0.]
[ -3.33066907e-16]
[ 0.]
[ 0.]
[  1.11022302e-16]
[  2.22044605e-16]
[]

In [149]: for nr,i in enumerate(x):
print y[nr] - y3[x2 == i]
.....:
.....:
[ -7.49400542e-16]
[  6.66133815e-16]
[  6.66133815e-16]
[ -1.38777878e-16]
[  3.33066907e-16]
[  8.88178420e-16]
[ -1.11022302e-16]
[  4.44089210e-16]
[  2.22044605e-16]
[ -3.88578059e-16]
[]

Maybe the two algorithms use different smoothness measures?  I'm
interested to know why this happens, but I don't have more time to
look at it right now, unfortunately.

Thanks
Stéfan

2008/5/21 Johann Rohwer <jr@sun.ac.za>:
> Hi,
>
> What is the difference (in terms of the underlying algorithms) between
> splines generated by sp.interpolate.interp1d and sp.interpolate.splrep/splev?
>
> As an example, when I do a simple spline interpolation of a sparsely sampled
> sin function, the two methods give me close but not identical results
> (especially close to the bounds of the x data the interpolated values differ).
>
> Code:
> import scipy as sp
> x=sp.linspace(0,10,11)
> y=sp.sin(x)
> x2=sp.linspace(0,10,201)
> tck=sp.interpolate.splrep(x,y,k=3)
> y2=sp.interpolate.splev(x2,tck)
> f=sp.interpolate.interp1d(x,y,kind=3)
> y3=f(x2)
>
> y2 and y3 differ!
>
> Regards
> Johann
> _______________________________________________
> SciPy-user mailing list
> SciPy-user@scipy.org
> http://projects.scipy.org/mailman/listinfo/scipy-user
>
```