Vincent
Vincent

Reputation: 60361

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 ?

Upvotes: 5

Views: 18808

Answers (1)

mgilson
mgilson

Reputation: 309831

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.

Upvotes: 13

Related Questions