如何将数组传递到Scipy插值RectBivariateSpline中? [英] How to pass arrays into Scipy Interpolate RectBivariateSpline?

查看:903
本文介绍了如何将数组传递到Scipy插值RectBivariateSpline中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个Scipy插值RectBivariateSpline,如下所示:

I am creating a Scipy Interpolate RectBivariateSpline as follows:

import numpy as np
from scipy.interpolate import RectBivariateSpline

x = np.array([1,2,3,4])
y = np.array([1,2,3,4,5])
vals = np.array([
    [4,1,4,4,2],
    [4,2,3,2,6],
    [3,7,4,3,5],
    [2,4,5,3,4]
])

rect_B_spline = RectBivariateSpline(x, y, vals)

然后我尝试传递x和y点的数组:

I then try to pass-in an array of x and y points:

a = np.array([3.2, 3.8, 2.2])
b = np.array([2.4, 4.3, 3.3])

print(rect_B_spline(a, b))

我收到如下错误:

Traceback (most recent call last):
  File "path/file", line 18, in <module>
    print(rect_B_spline(a, b))
  File "/path/scipy/interpolate/fitpack2.py", line 728, in __call__
    raise ValueError("Error code returned by bispev: %s" % ier)
ValueError: Error code returned by bispev: 10

当我将grid = False参数传递给方法时,此错误已纠正.

This error is remedied when I pass in the grid=False parameter to the method.

My impression from the documentation was that if the input grid coordinates form a regular grid, then the grid parameter should be True. Is there something I am missing?

推荐答案

是的,这里的文档可能有点薄弱.您使用的默认调用期望x和y定义网格点.就像创建样条线拟合的原始调用一样,它们必须严格按升序排列.然后它将返回样条曲线插值的完整网格.

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.

如果改用RectBivariateSpline.ev(xi,yi),则在调用rect_B_spline.ev(a,b)时,将获得在(xi [0],yi [0]),处的样条线的评估值. ..,(xi [j],yi [j])数据对.

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.

不太确定您要在此处-如果要完整的x by y网格,请将x,y中的每个点严格提升.如果希望得到一系列结果,请使用.ev(x,y)方法.

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.

这篇关于如何将数组传递到Scipy插值RectBivariateSpline中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆