【问题标题】:Error using SciPy 2D interpolator使用 SciPy 2D 插值器时出错
【发布时间】:2015-11-10 13:22:23
【问题描述】:

我有以下代码用于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 XY_product 是以下代码中的np.asarray(cart_product)cart_product = [] for element in itertools.product(ChromX,ChromY): cart_product.append(element)
  • @heltonbiker 另外,new_XY 如下:shifted_cart_product = zip(ChromX_shifted,ChromY_shifted)

标签: python scipy interpolation


【解决方案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]

【讨论】:

    猜你喜欢
    • 2011-07-05
    • 2013-03-04
    • 2019-06-23
    • 1970-01-01
    • 2011-09-17
    • 2023-04-03
    • 1970-01-01
    • 1970-01-01
    • 2016-06-17
    相关资源
    最近更新 更多