使用SciPy 2D插值器出现错误

3

我有以下代码进行 2D 插值:

myInterpolator = NearestNDInterpolator(XY_product, grid_data)

当我对新数据点运行此插值器时:
new_grid_data = myInterpolator(new_XY)

我遇到了以下错误:

xi = self._check_call_shape(xi)
File "interpnd.pyx", line 133, in 
    scipy.interpolate.interpnd.NDInterpolatorBase._check_call_shape 
    (scipy/interpolate/interpnd.c:3261)
ValueError: number of dimensions in xi does not match x

我该怎么解决这个问题?


你确定 XY_product 和尤其是 new_XY 是它们应该是的吗? - heltonbiker
@heltonbiker 在下面的代码中,XY_productnp.asarray(cart_product)cart_product = [] for element in itertools.product(ChromX,ChromY): cart_product.append(element) - A.M.
@heltonbiker 另外,new_XY 是以下内容:shifted_cart_product = zip(ChromX_shifted,ChromY_shifted) - A.M.
1个回答

1
这是关于 xi = self._check_call_shape(xi) 的描述,它能说明错误的来源:
def _check_call_shape(self, xi):
    xi = np.asanyarray(xi)
    if xi.shape[-1] != self.points.shape[1]:
        raise ValueError("number of dimensions in xi does not match x")
    return xi

这基本上意味着 xi.shape[-1] 应该等于 self.points.shape[1]

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接