Eld*_*ila 8 python spline scipy
我试图找到一个数字包,它将适合自然样条,最小化加权最小二乘法.
scipy中有一个包可以完成我想要的非自然样条.
import numpy as np
import matplotlib.pyplot as plt
from scipy import interpolate, randn
x = np.arange(0,5,1.0/6)
xs = np.arange(0,5,1.0/500)
y = np.sin(x+1) + .2*np.random.rand(len(x)) -.1
knots = np.array([1,2,3,4])
tck = interpolate.splrep(x,y,s=0,k=3,t=knots,task=-1)
ys = interpolate.splev(xs,tck,der=0)
plt.figure()
plt.plot(xs,ys,x,y,'x')
Run Code Online (Sandbox Code Playgroud)