Reputation: 25
I am predicting the path of a rolling ball using coordinates obtained from my webcam using openCV, by using scipy interpolate.
For the sake of simplicity, just normal arrays of x- and y-values are used.
I can only input x in the function to obtain y. However, I want to be able to get x, by using y as input. It is the inverse interpolated function I want, if that makes sense.
Currently it only works for an input of x, as seen in the code below at f(-100).
from scipy import interpolate
def f(x):
x_points = [ 0, 1, 2, 3, 4, 5]
y_points = [12,14,22,39,58,77]
coeff = interpolate.splrep(x_points, y_points)
return interpolate.splev(x, coeff)
print(f(-100))
Output when using x as input works just fine, with no error messages given.
Upvotes: 1
Views: 515
Reputation: 638
Have you tried switching the arguments? coeff = interpolate.splrep(y_points, x_points)
Upvotes: 1