如何在N维中使用scipy.interpolate.Rbf?
问题描述:
我正在尝试使用Rbf插入45维空间中定义的函数。我怎样才能将空间坐标插入scipy.interpolate.Rbf?如何在N维中使用scipy.interpolate.Rbf?
语法Rbf(x, y, z, d)
有没有把x, y, z
作为一个列表/阵列的方式,因为在我的情况下,它是x1, x2, ..., x45
?
答
如果你的观点和数据包含在一个单一的与NumPy阵列可以使用计算的功能时使用解包语法*array
在函数调用
In [4]: a = np.arange(30)
In [5]: a = a.reshape((6,5))
In [6]: a
Out[6]:
array([[ 0, 1, 2, 3, 4],
[ 5, 6, 7, 8, 9],
[10, 11, 12, 13, 14],
[15, 16, 17, 18, 19],
[20, 21, 22, 23, 24],
[25, 26, 27, 28, 29]])
In [7]: f = Rbf(*a)
In [8]: f((2,3),(7,8),(12,13),(17,18),(22,23))
Out[8]: array([ 27., 28.])
当然你也可以使用相同的语法通过Rbf
In [9]: x = np.array((4,9,14,19,24))
In [10]: f(*x)
Out[10]: array(29.0)