-1

What is the best way to do a quadratic spline in python? I used the interp1d, but this method is not what I pretend to do.

The is the example of python code:

from scipy.interpolate import interp1d 

x = [5,6,7,8,9,10,11]
y = [2,9,6,3,4,20,6]

xx = [1,2,3,4,5,6,7,8,9,10,11,12] 
f = interp1d(x, y, kind='quadratic') 
yy = f(xx)

Every time I run this code I get this error:

ValueError: A value in x_new is below the interpolation range.

Sam125
  • 1
  • 1
  • 2

2 Answers2

0

That error happens when you try to get a point out of the interpolation range. For instance if you only have data between 5 and 11 you only can interpolate within this range (otherwise we would be talking about extrapolations). However the function "scipy.interpolate.CubicSpline" interpolates and extrapolates, so you can get results out of the range.

0

Try adding the parameter fill_value:

f= interp1d(x, y, kind='quadratic', fill_value='extrapolate')

Values of xx: 1,2,34 and 12 are out of the initial data you provided so the spline must be built in order to handle this.

Adrien Mau
  • 181
  • 5