因此,我想避免每次都重新计算这些权重.有没有办法做到这一点?即,从一个非结构化网格多次插值到另一个非结构化网格,两者均保持不变,以避免重新计算scipy.interpolate.griddata(或等效值)的内部?解决方案一种解决方案是使用 LinearNDInterpolator 具有预先计算的 Delaunay 三角剖分:from scipy.spatial import Delaunayfrom scipy.interpolate import LinearNDInterpolatortri = Delaunay(mesh1) # Compute the triangulation# Perform the interpolation with the given values:interpolator = LinearNDInterpolator(tri, values_mesh1)values_mesh2 = interpolator(mesh2) mesh1是一个(点数*暗)数组.注意: 可用于非线性插值. griddata使用LinearNDInterpolator或CloughTocher2DInterpolator.I am trying to interpolate data from an unstructured mesh M1 to another unstructured mesh M2. For this, scipy.interpolate.griddata seems good.However, I will need to interpolate many times from M1 to M2, changing only the data not the meshes. I guess that, internally, the scipy.interpolate.griddata defines some weight coefficients when interpolating from M1 to M2 and that this may be one of the expensive parts of the computation.Therefore, I would like to avoid re-compute these weigths each time. Is there a way to do this? I.e., interpolating many times from one unstructured mesh to another unstructured mesh, both kept constant, avoiding to re-compute the internals of scipy.interpolate.griddata (or equivalent)? 解决方案 A solution is to use the LinearNDInterpolator Scipy function with a pre-computed Delaunay triangulation:from scipy.spatial import Delaunayfrom scipy.interpolate import LinearNDInterpolatortri = Delaunay(mesh1) # Compute the triangulation# Perform the interpolation with the given values:interpolator = LinearNDInterpolator(tri, values_mesh1)values_mesh2 = interpolator(mesh2)mesh1 is a (number of points * dim) array.Note: CloughTocher2DInterpolator could be used for non-linear interpolation. griddata uses either LinearNDInterpolator or CloughTocher2DInterpolator. 这篇关于存储scipy网格数据使用的权重以供重用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
09-06 00:14