scipy.interpolate。bisplrep
參考: http://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.bisplrep.html
import scipy
import math
import numpy
from scipy import interpolate
x= [1,2,3,4,5,6]
y= [10,20,30]
Y = numpy.array([[i]*len(x) for i in y])
X = numpy.array([x for i in y])
Z = numpy.array([[2.3,3.4,5.6,7.8,9.6,11.2],
[4.3,5.4,7.6,9.8,11.6,13.2],
[6.3,7.4,8.6,10.8,13.6,15.2]])
tck = interpolate.bisplrep(X,Y,Z)
print interpolate.bisplev(3.5,15,tck)
7.84921875
編輯:
上層溶液不給你完美契合。 檢查
print interpolate.bisplev(x,y,tck)
[[ 2.2531746 4.2531746 6.39603175]
[ 3.54126984 5.54126984 7.11269841]
[ 5.5031746 7.5031746 8.78888889]
[ 7.71111111 9.71111111 10.9968254 ]
[ 9.73730159 11.73730159 13.30873016]
[ 11.15396825 13.15396825 15.2968254 ]]
克服5RD度的在x和第二程度這個插值絲毫polyinomials在y方向上
tck = interpolate.bisplrep(X,Y,Z,kx=5,ky=2)
print interpolate.bisplev(x,y,tck)
[[ 2.3 4.3 6.3]
[ 3.4 5.4 7.4]
[ 5.6 7.6 8.6]
[ 7.8 9.8 10.8]
[ 9.6 11.6 13.6]
[ 11.2 13.2 15.2]]
這收率
print interpolate.bisplev(3.5,15,tck)
7.88671875
繪圖:
參考http://matplotlib.sourceforge.net/examples/mplot3d/surface3d_demo.html
個
fig = plt.figure()
ax = Axes3D(fig)
ax.plot_surface(X, Y, Z,rstride=1, cstride=1, cmap=cm.jet)
plt.show()
嘿,謝謝我認爲這完美的作品 還有一個問題,我如何在XY z軸上繪製它們 – VASUDEVAN 2009-12-30 16:30:37
請注意,scipy.interpolate。*(FITPACK)樣條曲線可能不會插值, 即可能不經過輸入數據;請參閱平滑度參數s。 Imho FITPACK比doc更強大,所以開始簡單(Martelli):kx = ky = 1,s = 0。 – denis 2010-01-03 11:01:46