【问题标题】:Scipy interp2d interpolate masked fill valuesScipy interp2d 插值蒙版填充值
【发布时间】:2016-12-23 08:49:36
【问题描述】:

我想插入数据 (120*120) 以获得输出数据 (1200*1200)。

这样我使用scipy.interpolate.interp2d

以下是我的输入数据,其中 255 对应填充值,我在插值之前屏蔽了这些值。

我正在使用下面的代码:

tck = interp2d(np.linspace(0, 1200, data.shape[1]),
               np.linspace(0, 1200, data.shape[0]),
               data,
               fill_value=255)
data = tck(range(1200), range(1200))
data = np.ma.MaskedArray(data, data == 255)

我得到以下结果:

填充值已被插值。

如何在不插入填充值的情况下插入我的数据?

【问题讨论】:

    标签: python arrays numpy scipy interpolation


    【解决方案1】:

    我找到了scipy.interpolate.griddata 的解决方案,但我不确定这是最好的解决方案。

    我使用 nearest 方法参数对数据进行插值,该参数返回最接近插值点的数据点处的值。

    points = np.meshgrid(np.linspace(0, 1200, data.shape[1]),
                         np.linspace(0, 1200, data.shape[0]))
    points = zip(points[0].flatten(), points[1].flatten())
    xi = np.meshgrid(np.arange(1200), np.arange(1200))
    xi = zip(xi[0].flatten(), xi[1].flatten())
    
    tck = griddata(np.array(points), data.flatten(), np.array(xi), method='nearest')
    data = tck.reshape((1200, 1200))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-12
      相关资源
      最近更新 更多