Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Choosing between numpy.interp vs scipy.interpolate.interp1d (with kind='linear')

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.

like image 388
sotrue Avatar asked Aug 29 '15 20:08

sotrue


People also ask

Is interp1d linear interpolation?

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.

What does Scipy interpolate interp1d return?

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.

What is interpolate interp1d?

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.

What is Scipy interpolate in Python?

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.


2 Answers

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).

like image 111
ev-br Avatar answered Sep 21 '22 16:09

ev-br


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

like image 29
Moritz Avatar answered Sep 23 '22 16:09

Moritz