arrays - Interpolation without specifying indices in Python -
i have 2 arrays of same length, array x , array y. want find value of y corresponding x=0.56. not value present in array x. python find closest value larger 0.56 (and corresponding y value) , closest value smaller 0.56 (and corresponding y value). interpolate find value of y when x 0.56.
this done when find indices of 2 x values , corresponding y values myself , input them python (see following bit of code). there way python find indices itself?
#interpolation: def effective_height(h1,h2,g1,g2): return (h1 + (((0.56-g1)/(g2-g1))*(h2-h1))) eff_alt1 = effective_height(x[12],x[13],y[12],y[13])
in bit of code, had find indices [12] , [13] corresponding closest smaller value 0.56 , closest larger value 0.56.
now looking similar technique tell python interpolate between 2 values of x x=0.56 , print corresponding value of y when x=0.56.
i have looked @ scipy's interpolate don't think in case, although further clarification on how can use in case helpful too.
does numpy interp
want?:
import numpy np x = [0,1,2] y = [2,3,4] np.interp(0.56, x, y) out[81]: 2.56
Comments
Post a Comment