interpolate linear array to non linear array using python numpy or scipy -
i have arrays:
a linear one;
x = array([ 0. , 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1. , 1.1, 1.2, 1.3, 1.4])
and corresponding result non-linear one;
y = array([ 13.07, 13.7 , 14.35, 14.92, 15.5 , 16.05, 16.56, 17.12, 17.62, 18.08, 18.55, 19.02, 19.45, 19.88, 20.25])
now: want convert y linearly spaced array , find corresponding interpolated values of x
.
i.e. find x when
y = array([ 13. , 13.5, 14. , 14.5, 15. , 15.5, 16. , 16.5, 17. , 17.5, 18. , 18.5, 19. , 19.5, 20. ])
thanks in advance.
i use following method using interp function in numpy:
ynew = np.linspace(np.min(y), np.max(y), len(y)) xnew = np.interp(ynew, y, x)
i.e. exchanging x , y in np.interp function.
is correct ? or break down condition.
unless i'm missing something, case calls simple invocation of numpy.interp
. want predict x
y
reverse of how people variable definitions, other wrinkle, need is:
import numpy np x = np.array([ 0. , 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1. , 1.1, 1.2, 1.3, 1.4]) y = np.array([ 13.07, 13.7 , 14.35, 14.92, 15.5 , 16.05, 16.56, 17.12, 17.62, 18.08, 18.55, 19.02, 19.45, 19.88, 20.25]) ynew = np.array([ 13. , 13.5, 14. , 14.5, 15. , 15.5, 16. , 16.5, 17. , 17.5, 18. , 18.5, 19. , 19.5, 20. ]) xnew = np.interp(ynew, y, x) print xnew
which gives ouput:
[ 0. 0.06825397 0.14615385 0.22631579 0.3137931 0.4 0.49090909 0.58823529 0.67857143 0.776 0.8826087 0.9893617 1.09574468 1.21162791 1.33243243]
Comments
Post a Comment