I am currently writing a python definition called f_from_data that uses the interpolation search point on the string so far, I wrote this:
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
This gives me what I want to do this so that I can enter:
f = f_from_data([3, 4, 6], [0, 1, 2]) print f(3) >>>0.0
How can I do it? I looked around, but could not find anything, because I think it is really trivial, but I'm just missing something.
python numpy callable
GBA13
source share