I'm trying to choose between numpy.interp
vs scipy.interpolate.interp1d
(with kind='linear'
of course). I realize they have different interfaces but that doesn't matter much to me (I can code around either interface). I'm wondering whether there are other differences I should be aware of. Thanks.
interp. One-dimensional linear interpolation for monotonically increasing sample points. Returns the one-dimensional piecewise linear interpolant to a function with given discrete data points (xp, fp), evaluated at x.
This class returns a function whose call method uses interpolation to find the value of new points. A 1-D array of monotonically increasing real values. A N-D array of real values.
The interp1d() function of scipy. interpolate package is used to interpolate a 1-D function. It takes arrays of values such as x and y to approximate some function y = f(x) and then uses interpolation to find the value of new points.
The scipy. interpolate is a module in Python SciPy consisting of classes, spline functions, and univariate and multivariate interpolation classes. Interpolation is done in many ways some of them are : 1-D Interpolation. Spline Interpolation.
Numpy.interp does not handle complex-valued data or ndim>1, while scipy.interp1d does both. OTOH, numpy's interpolator is much faster (and is likely faster still in more recent numpy version).
While numpy returns an array with discrete datapoints, 'interp1d' returns a function. You can use the generated function later in your code as often as you want. Furthermore, you can choose other methods than linear interpoationn
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With