Interpolation technique used in numpy

560 Views Asked by At

What is the technique used by the numpy interp() function?

So using the following points

import numpy as np

x = [4.5]
xp = [4, 5, 4, 3]
yp = [2, 4, 6, 5]

result = np.interp(x, xp, yp)

print(result) #result = 5.0

When I find the interpolation of x the value is 4.5

But if my points are these 3 xp = [4, 5, 4] e yp = [2, 4, 6] the value will be 6

import numpy as np

x = [4.5]
xp = [4, 5, 4]
yp = [2, 4, 6]

result = np.interp(x, xp, yp)

print(result) #result = 6.0
1

There are 1 best solutions below

0
On BEST ANSWER

Your xp array is not strictly increasing. In fact, you even have a repeated value with different corresponding fp values! In this case, the behavior is undefined.

From the numpy.interp documentation:

xp: 1-D sequence of floats

The x-coordinates of the data points, must be increasing if argument period is not specified.