[SciPy-user] interpolate

Michael McNeil Forbes mforbes at physics.ubc.ca
Sat Nov 15 16:54:15 EST 2008


The splrep function seems to require the input data to be sorted  
along the abscissa.

tck2=interpolate.splrep(scipy.array([2.0,8.2]),scipy.array 
([4.0,1.0]),k=1)

You can use argsort to sort the abscissa and then using the inds to  
sort the dependent variable:

import numpy as np
import scipy as sp
x = np.array([8.2, 2.0])
y = np.array([1.0, 4.0])

inds = np.argsort(x)
tck = sp.interpolate.splrep(x[inds], y[inds], k=1)

Michael.

On Nov 14, 2008, at 3:38 PM, AndrewF wrote:

>
> Why does
>
> tck1=interpolate.splrep(scipy.array([1.0,2.0]),scipy.array 
> ([1.0,4.0]),k=1)
>
> work okay, but
>
> tck2=interpolate.splrep(scipy.array([8.2,2.0]),scipy.array 
> ([1.0,4.0]),k=1)
>
> does not?
>
> I ultimately want to interpolate a more complicated, non-linear  
> data set,
> but here I am trying to reduce the problem to the simplest possible  
> level.
>
> Thanks.
> -- 
> View this message in context: http://www.nabble.com/interpolate- 
> tp20509445p20509445.html
> Sent from the Scipy-User mailing list archive at Nabble.com.
>
> _______________________________________________
> SciPy-user mailing list
> SciPy-user at scipy.org
> http://projects.scipy.org/mailman/listinfo/scipy-user




More information about the SciPy-User mailing list