且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在 B 样条基础上查询双变量样条上的多个点

更新时间:2023-02-26 16:42:13

简答:替换

for i in xrange(cv.shape[1]):
    tck = (u_kv, v_kv, cv[:,i], uDegree,vDegree)
    for j in xrange(u.shape[0]):
        position[j,i] = si.bisplev(u[j],v[j], tck)

for i in xrange(cv.shape[1]):
    position[:, i] = si.dfitpack.bispeu(u_kv, v_kv, cv[:,i], uDegree, vDegree, u, v)[0]

说明

bisplev 确实接受数组为 si.bisplev(u, v, tck),但它会将它们解释为定义 xy 网格.因此,uv 必须按升序排序,并且将对所有对 (u[j], v[k])进行评估code>,输出是一个二维数组.这不是你想要的;求值次数的平方可能不好,并且从返回的二维数组中提取您实际想要的值并不容易(它们不一定在对角线上,因为您的 u、v 没有开始排序).

Explanation

bisplev does accept arrays as si.bisplev(u, v, tck), but it interprets them as defining an xy-grid. Hence, u and v must be sorted in ascending order, and evaluation will be performed on all pairs (u[j], v[k]), the output being a 2D array of values. This is not what you want; squaring the number of evaluations is probably bad, and it's not going to be easy to extract the values you actually want from the 2D array returned (they are not necessarily on the diagonal, since your u, v were not sorted to begin with).

但是 SmoothBivariateSpline 的调用方法 包含一个布尔参数grid,将which 设置为False 使其仅评估(u[j], v[j]) 对.向量 u、v 不再需要排序,但现在它们必须具有相同的大小.

But the call method of SmoothBivariateSpline includes a boolean parameter grid, setting which to False makes it just evaluate the spline at (u[j], v[j]) pairs. The vectors u, v no longer need to be sorted, but now they must be of the same size.

但是您正在准备自己的tck.这提供了两种方法:尝试使用手工 tck 实例化 SmoothBivariateSpline;或阅读 它的调用方法 并在参数grid 设置为False 时执行它的操作.我选择了后一种方法.

But you are preparing your own tck. This presents two approaches: seek to instantiate SmoothBivariateSpline with hand-made tck; or read the source of its call method and do what it does when the parameter grid is set to False. I went with the latter approach.