存储scipy网格数据使用的权重以供重用

时间:2018-08-15 11:53:32

标签: optimization scipy interpolation

我正在尝试将数据从非结构化网格 M1 插值到另一个非结构化网格 M2 。为此,scipy.interpolate.griddata似乎不错。

但是,我需要多次从 M1 插值到 M2 ,仅更改数据而不更改网格。我想在内部,scipy.interpolate.griddata在从 M1 插值到 M2 时定义了一些权重系数,这可能是计算中昂贵的部分之一。

因此,我想避免每次都重新计算这些权重。有没有办法做到这一点?也就是说,要从一个非结构化网格多次插值到另一个非结构化网格,两者都保持不变,从而避免重新计算scipy.interpolate.griddata(或等效值)的内部?

1 个答案:

答案 0 :(得分:1)

一种解决方案是将LinearNDInterpolator Scipy函数与预先计算的Delaunay三角剖分一起使用:

try:
    label, sentence = line.strip().split("\t".encode())
except ValueError:
    print(f'Error line: {line}')
    continue

from scipy.spatial import Delaunay from scipy.interpolate import LinearNDInterpolator tri = Delaunay(mesh1) # Compute the triangulation # Perform the interpolation with the given values: interpolator = LinearNDInterpolator(tri, values_mesh1) values_mesh2 = interpolator(mesh2) 是一个(点数*暗)数组。

注意:CloughTocher2DInterpolator可用于非线性插值。 mesh1使用griddataLinearNDInterpolator