我需要一个等效于interp2 MATLAB 函数的 Python。我试图让这个MATLAB 示例在 Python 中工作,但我做不到。
import numpy as np
from scipy.interpolate import interp2d
from scipy.interpolate import RectBivariateSpline
service = np.array(range(10, 31, 10))
years = np.array(range(1950, 1991, 10))
wage = np.array([[150.6970,199.5920,187.6250],
[179.3230, 195.0720, 250.2870],
[203.2120, 179.0920, 322.7670],
[226.5050, 153.7060, 426.7300],
[249.6330, 120.2810, 598.2430]])
ip = RectBivariateSpline(years, service, wage)
print(ip(15, 1975))
但是我得到了这个我无法解决的错误(在 RectBivariateSpline 中):
Traceback (most recent call last):
File "/Users/andrea/Documents/workspace/PythonProjects/pyArmBot/src/foo.py", line 15, in <module>
ip = RectBivariateSpline(years, service, wage)
File "/Library/Python/2.7/site-packages/scipy-0.10.1-py2.7-macosx-10.7-intel.egg/scipy/interpolate/fitpack2.py", line 728, in __init__
kx,ky,s)