Home > Mobile >  Python equivalent of Excel's Cubic interpolation
Python equivalent of Excel's Cubic interpolation

Time:01-13

In Excel there is a function called Cubicinterpolation(). I am looking for an equivalent function in Python which should be able to closely match the results.

Is there any such function/method available with Python?

CodePudding user response:

You can use scipy package and interp1d function:

# pip install scipy
import numpy as np
from scipy import interpolate

x = np.arange(0, 10)
y = np.exp(-x/3.0)
f = interpolate.interp1d(x, y, kind='cubic')

Usage:

>>> f(1.5)
array(0.60644424)

>>> f([2.5, 4.5])
array([0.4346027 , 0.22312461])
  •  Tags:  
  • Related