Код: Выделить всё
import numpy as np
import pandas as pd
from scipy.interpolate import RegularGridInterpolator
import io
xi, yi = 100, 100; # test points I want to evaluate the interpolator object at
# the 2D data copied from google sheets and pasted into Jupyter notebook generates this dataframe:
values = pd.read_csv(io.StringIO('''
223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223
223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223
223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223
223,223,223,223,223,223,223,223,221,220,219,218,217,217,215,215,215,217,217,218,218,219,220,221,222,222,222
223,223,223,223,223,223,223,223,223,219,218,217,215,215,210,210,210,215,217,217,217,218,219,220,221,222,222
223,223,223,223,223,223,223,223,223,218,217,217,215,210,207,207,207,210,215,215,217,218,219,219,220,221,222
223,223,223,223,223,223,223,223,218,217,223,215,210,207,205,205,207,207,210,210,215,217,218,219,220,221,222
223,223,223,223,223,223,223,223,218,217,216,215,207,205,203,203,205,207,207,210,215,217,218,219,220,221,222
223,223,223,223,223,223,223,223,218,217,216,215,207,205,203,203,205,207,210,212,215,217,218,219,220,221,222
223,223,223,223,223,223,223,223,223,218,217,217,215,207,205,205,207,210,212,215,217,218,219,220,221,222,223
223,223,223,223,223,223,223,223,223,223,218,218,217,215,207,207,215,215,215,217,218,219,220,221,222,223,223
223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223
223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223
223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223
223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223
223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223
223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223
223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223,223
'''), header=None);
# these are the X and Y values corresponding to the X and Y dimensions of the data (values).
X = np.linspace(0, 2600, values.shape[1]);
Y = np.linspace(0, 1700, values.shape[0]);
Yi, Xi = np.meshgrid(Y, X);
interp = RegularGridInterpolator((Y, X), values); # X and Y are switched here because Y corresponds to the rows of the dataframe and X corresponds to the columns but I'm matching the SciPy syntax.
interp(np.array([[xi], [yi]]).T) # this is the portion I'm having trouble with
Код, описанный выше, возвращает следующую ошибку:< /p>
Код: Выделить всё
InvalidIndexError: (array([1]), array([1]))
Подробнее здесь: https://stackoverflow.com/questions/787 ... for-2d-int