小编rko*_*lla的帖子

使用scipy.interpolate.LSQBivariateSplines将二维样条拟合到带有间隙的噪声数据

我有一个在网格上有矩形数据的numpy数组,并希望在它上面插入二维样条来重现大规模变化,同时消除所有/大部分噪声.数据还有一些区域标记为NaN值无效.

我尝试使用scipy.interpolate.RectBivariateSpline函数,但是差距搞砸了结果.所以我尝试使用同一个包中的LSQBivariateSpline函数,希望当我将所有NaN像素的权重设置为0时,它会简单地忽略它们.但是,当我遇到以下错误时,我不知道如何避免:

我的代码是:

# some preparation, loading data and stuff
# all my data is stored in 'data'

# Create the knots (10 knots in each direction, making 100 total
xcoord = numpy.linspace(5, data.shape[0]-5, 10)
ycoord = numpy.linspace(5, data.shape[1]-5, 10)

# Create all weights, and set them to 0 when the data is NaN
weights = numpy.ones(data.shape)
weights[numpy.isnan(data)] = 1e-15  # weights must be >0

# LSQBivariateSpline needs x and y coordinates as 1-D arrays
x, y = numpy.indices(data.shape)
spline_fit …
Run Code Online (Sandbox Code Playgroud)

python interpolation spline scipy data-fitting

4
推荐指数
1
解决办法
3319
查看次数

标签 统计

data-fitting ×1

interpolation ×1

python ×1

scipy ×1

spline ×1