How to pass arrays into Scipy Interpolate RectBivariateSpline?

限于喜欢 提交于 2019-12-01 18:58:28

Yes, the documentation is perhaps a bit weak here. The default call that you are using expects that x and y define grid points. Like the original call to create the spline fit, these need to be in strictly ascending order. It will then return the full grid of spline interpolations.

If you instead use RectBivariateSpline.ev(xi,yi), in your case call rect_B_spline.ev(a,b), you get the spline evaluated at each of (xi[0],yi[0]), ..., (xi[j],yi[j]) data pairs.

Not quite sure which you wanted here - if you want a full x by y grid, make the points in each of x,y to be strictly ascending. If you want the results at a series of points, use the .ev(x,y) method.

This works:

RectBivariateSpline(x,y,vals)([2.2,3.2,3.8],[2.4,3.3,4.3],grid=True)

array([[ 3.197056,  2.75356 ,  2.38796 ],
       [ 6.408896,  3.56696 ,  3.46736 ],
       [ 5.768704,  4.33264 ,  3.10824 ]])

RectBivariateSpline(x[:,None],y,vals)(a,b,grid=False)
# array([ 6.408896,  3.10824 ,  2.75356 ])

I sorted the values, as specified in the docs:

If grid is True: evaluate spline at the grid points defined by the coordinate arrays x, y. The arrays must be sorted to increasing order.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!