2

I am in the process of converting some matlab code to python when I ran into the spline function in matlab. I assumed that numpy would have something similar but all I can find on google is scipy.interpolate, which has so many options I dont even know where to start. http://docs.scipy.org/doc/scipy/reference/interpolate.html Is there an exact equivalent to the matlab spline? Since I need it to run for various cases there is not one single test case, so in the worst case I need to recode the function and that will take unnecessary amounts of time.

Thanks

Edit:

So i have tried the examples of the answers so far, but i dont see how they are similar, for example spline(x,y) in matlab returns:

>> spline(x,y)

ans = 

      form: 'pp'
    breaks: [0 1 2 3 4 5 6 7 8 9]
     coefs: [9x4 double]
    pieces: 9
     order: 4
       dim: 1

1 Answer 1

3

SciPy:

scipy.interpolate.UnivariateSpline

http://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.UnivariateSpline.html#scipy.interpolate.UnivariateSpline

Note that it returns an interpolator (function) not interpolated values. You have to make a call to the resulting function:

spline = UnivariateSpline(x, y)
yy = spline(xx)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.