Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Array interpolation in python?

I have two arrays :

array_x = [x1, x2, x3, x4... xn]
array_y = [y1, y2, y3, y4... yn]

I would like to have a function f(array_x, array_y, value_x) that returns the value_y associated to the value_x by interpolation into the arrays.

How to do that ?

like image 799
Vincent Avatar asked Dec 20 '22 08:12

Vincent


1 Answers

I think that numpy.interp is exactly what you want. e.g.:

numpy.interp(value_x,array_x,array_y)

Note that here value_x can be a scalar or another array-like value. If it is an array-like value, you will be returned an array of corresponding interpolated values.

like image 144
mgilson Avatar answered Dec 26 '22 11:12

mgilson