简体   繁体   中英

Matlab spline function in python

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

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM