【发布时间】:2015-02-19 22:20:29
【问题描述】:
我目前正在编写一个名为 f_from_data 的 python 定义,它在一条线上使用插值查找点到目前为止我已经写了这个:
def f_from_data(xs, ys, x):
xfine = np.linspace(min(xs), max(xs), 10000)
y0 = inter.interp1d(xs, ys, kind = 'linear')
ans = (y0(xfine))[numpy.searchsorted(xfine, x)]
ans = round(ans,2)
return ans
这给了我我想要的东西,所以我可以输入:
f = f_from_data([3, 4, 6], [0, 1, 2])
print f(3)
>>>0.0
我该怎么做呢?我环顾四周,但似乎找不到任何东西,因为我认为这真的很微不足道,但我只是错过了一些东西。
【问题讨论】:
-
仅供参考,此过程称为partial function application。