我使用scipy.interpolate.Rbf,它返回一个函数,将大量RBF拟合到不同的点集,并将其输出存储在函数向量中,如下所示
import scipy.interpolate as interp
for i in range(0,n):
# Gets data points for this particular iteration
data = get_data(i)
# Fits RBF to data points
zfun_smooth_rbf = interp.Rbf(data[:, 0], data[:, 1], data[:, 2], function='linear', smooth=0)
# Appends RBF function
rbf_fit.append(zfun_smooth_rbf)
然后我有兴趣运行所有的函数来回归每个计算出的RBF的值。目前我使用一个foor循环策略,类似于this问题中的答案,但这远不是理想的,因为它基本上是按顺序运行的
^{pr2}$有没有办法只打一个电话打这个电话?换句话说,我需要同时调用数组中存储的所有函数。像c = self.rbf_fit[:](x,y)
之类的?在
我将尝试将2
rbfi
的__call__
组合成一个调用。在按照文档中的说明制作样本:
^{pr2}$制作第二个样本:
查看
rbfi
的关键属性:在
__call__
中构造变量:用一个调用计算两个
rbfi
的norm
,方法是连接xi
数组:现在对
nodes' and
点执行相同的操作:哦。我们需要两组20个;这一次适合所有100个节点。我需要做些整形。在
^{8}$2
rbfi
的_function
可调用项不同,因此我分别使用它们:有了更多的样本,这个列表将被构建成一个列表理解。在
现在我可以对组合的
rbfi
执行np.dot
:所以我设法用一个
In [138]
替换In [149]
迭代。我不知道这是否能节省时间。这可能取决于_function
调用与其他调用rbfi.__call__
相比的开销有多大。在在我的例子中
我不知道你的参数,
function='linear', smooth=0
是否有影响。如果各自的_function
属性相同,那么我可以用这就提供了一个关于如何加快
rbfi
的迭代的想法,甚至可以用“vector”操作来替换它。在看起来,对于默认函数,区别仅在于
epsilon
值:相关问题 更多 >
编程相关推荐