I am currently writing a python definition called f_from_data which uses interpolation find point on a line so far I have written 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 is giving me what I want to I need to make it so I can enter:
f = f_from_data([3, 4, 6], [0, 1, 2])
print f(3)
>>>0.0
How do I go about doing this? I've looked around but can't seem to find anything as I think its really trivial but I'm just missing somthing.