Home > Blockchain >  Interpolation technique used in numpy
Interpolation technique used in numpy

Time:08-24

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

CodePudding user response:

In your input the values in xp are not in ascending order, so for this example the question is moot. Check out the enter image description here

In your case;

xp = [4, 5, 4, 3]
fp = [2, 4, 6, 5]
plt.figure(figsize=(9, 9))
plt.plot([0, 1, 2, 3.5, 4, 5, 5.5, 6, 6.5], np.interp([0, 1, 2, 3.5, 4, 5, 5.5, 6, 6.5], xp, fp))
plt.scatter(xp, fp, c='red')
plt.show()

enter image description here

  • Related