Array interpolation in python?
10,249
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.
Author by
Vincent
Researcher, astrophysicist, computer scientist, programming language expert, software architect and C++ standardization committee member. LinkedIn: https://www.linkedin.com/in/vincent-reverdy
Updated on June 04, 2022Comments
-
Vincent almost 2 years
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 thevalue_y
associated to thevalue_x
by interpolation into the arrays.How to do that ?
-
Adrians Netlis over 8 yearsHm... How to write this my own? Some people complain that they got no numpy, so I need this myself...
-
mgilson over 8 yearsLinear interpolation is a pretty well known algorithm. From there, it's just a matter of searching the array (could use bisection) for the elements that bound the value where you want to interpolate to -- With that said, for any real mathematical analysis,
numpy
seems to be the standard. Is there a reason why those people can't install numpy? -
Adrians Netlis over 8 yearsWhen I make game, I wouldn't want to place a tester for numpy(if it is installed) and installer(if it is not). So...