Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error using SciPy 2D interpolator

I have the following piece of code for 2D interpolation:

myInterpolator = NearestNDInterpolator(XY_product, grid_data)

When I run this interpolator for a new data point:

new_grid_data = myInterpolator(new_XY)

I get the following error:

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

How do I fix this?

like image 884
A.M. Avatar asked Jan 28 '26 17:01

A.M.


1 Answers

Here is the description of xi = self._check_call_shape(xi) which illuminates where the error is coming from:

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

This basically means that xi.shape[-1] should be equal to self.points.shape[1].

like image 147
A.M. Avatar answered Jan 30 '26 09:01

A.M.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!