【问题标题】:Python 2d interpolation for masked or unordered input data用于掩码或无序输入数据的 Python 2d 插值
【发布时间】:2021-10-02 10:26:01
【问题描述】:

我拥有的数据是频率 (f) 和 theta *(th) *它们是对应于二维物体光束的坐标 (b) 。即:(f_i, th_i) == b_ii.

我使用scipy.interpolate.interp2d 设置了二维插值。效果很好,直到我按降序使用新输入数据或使用屏蔽数组 (屏蔽值变为 0 重新排序数据,使零值在前。

如果我重新应用掩码,由于数据的排序,它会出现在不正确的位置。有没有人有一个简单的解决方法?

注意: 新的输入值在原始网格设置的范围内。

【问题讨论】:

    标签: python scipy interpolation masked-array


    【解决方案1】:

    来自Scipy-interp2d returned function sorts input argument automatically and undesirably的解决方案

    根据上面提交的链接

    from scipy.interpolate import interp2d
    import numpy as np
    
    class unsorted_interp2d(interp2d):
        def __call__(self, x, y, dx=0, dy=0):
            unsorted_idxs = np.argsort(np.argsort(x))
            return interp2d.__call__(self, x, y, dx=dx, dy=dy)[:,unsorted_idxs]
    

    刚刚将 [unsorted_idxs] 更改为 [:,unsorted_idxs] 以适用于 2d 对象中的所有 x 值

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-11-14
      • 1970-01-01
      • 1970-01-01
      • 2017-11-07
      • 2016-06-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多