简体   繁体   English

python中的Matlab样条函数

[英]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. 当我在matlab中遇到样条函数时,我正在将一些matlab代码转换为python。 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. 我以为numpy会有类似的东西,但是我在google上只能找到scipy.interpolate,它有很多选择,我什至不知道从哪里开始。 http://docs.scipy.org/doc/scipy/reference/interpolate.html Is there an exact equivalent to the matlab spline? http://docs.scipy.org/doc/scipy/reference/interpolate.html是否有与matlab样条线完全相同的东西? 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: 因此,到目前为止,我已经尝试了答案的示例,但是我看不到它们的相似之处,例如matlab中的spline(x,y)返回:

>> 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的:

scipy.interpolate.UnivariateSpline scipy.interpolate.UnivariateSpline

http://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.UnivariateSpline.html#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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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