云数据点的加权一维插值

2024-04-19 02:30:32 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个数据点云(x,y),我想插值和平滑。你知道吗

目前,我正在使用scipy:

from scipy.interpolate import interp1d
from scipy.signal import savgol_filter

spl = interp1d(Cloud[:,1], Cloud[:,0]) # interpolation
x = np.linspace(Cloud[:,1].min(), Cloud[:,1].max(), 1000)
smoothed = savgol_filter(spl(x), 21, 1) #smoothing

这是工作得很好,除了我想给一些权重的数据点在interp1d。对处理这个问题的另一个函数有什么建议吗?你知道吗

基本上,我认为我可以根据云的权重乘以每个点的出现次数,但这并不是很优化,因为它增加了很多要插值的点的数量,并且减慢了算法的速度。。你知道吗


Tags: 数据fromimportcloudsignalnpscipyfilter
1条回答
网友
1楼 · 发布于 2024-04-19 02:30:32

默认的interp1d使用linear interpolation,也就是说,它只计算两点之间的一条线。在这种情况下,加权插值在数学上没有多大意义——在欧几里德空间中,只有一种方法可以在两点之间画一条直线。你知道吗

根据您的目标,您可以研究其他插值方法,例如B样条曲线。然后可以使用scipy的scipy.interpolate.splrep并设置w参数:

w - Strictly positive rank-1 array of weights the same length as x and y. The weights are used in computing the weighted least-squares spline fit. If the errors in the y values have standard-deviation given by the vector d, then w should be 1/d. Default is ones(len(x)).

相关问题 更多 >