Python SciPy Sub Package Interpolate

Python SciPy Sub Package Interpolate


Interpolation is the process of finding a value between two points on a line or a curve. To help us remember what it means, we should think of the first part of the word, 'inter,' as meaning 'enter,' which reminds us to look 'inside' the data we originally had. This tool, interpolation, is not only useful in statistics, but is also useful in science, business, or when there is a need to predict values that fall within two existing data points.

Let us take an example to see how and why Interpolation is used and how it is implemented.



Now, we have two arrays. Assuming those two arrays as the two dimensions of the points in space, let us plot using the following program and see how they look like.


1-D Interpolation

The interp1d class in the scipy.interpolate is a convenient method to create a function based on fixed data points, which can be evaluated anywhere within the domain defined by the given data using linear interpolation.


In the above program, we have created two function fun1 and fun2. The variable x contains the sample points, and variable y contains the corresponding values. The third variable kind represents the types of interpolation techniques. There are various methods of interpolation.


To draw smooth curves through data points, drafters once used thin flexible strips of wood, hard rubber, metal, or plastic called mechanical splines. To use a mechanical spline, pins were placed at a judicious selection of points along a curve in design, and then the spline was bent so that it touched each of these pins.

Clearly, with this construction, the spline interpolates the curve at these pins. It can be used to reproduce the curve in other drawings. The points where the pins are located are called knots. We can change the shape of the curve defined by the spline by adjusting the location of the knots.

Univariate Spline

One-dimensional smoothing spline fits a given set of data points. The UnivariateSpline class in scipy.interpolate is a convenient method to create a function, based on fixed data points class %u2013 scipy.interpolate.



w :-Specifies the weights for spline fitting. Must be positive. If none (default), weights are all equal.

s :- Specifies the number of knots by specifying a smoothing condition.

k :- Degree of the smoothing spline. Must be <= 5. The default is k = 3, a cubic spline.

Ext :%u2212 Controls the extrapolation mode for elements not in the interval defined by the knot sequence.

  • if ext = 0 or 'extrapolate', returns the extrapolated value.

  • if ext = 1 or 'zero', returns 0

  • if ext = 2 or 'raise', raises a ValueError

  • if ext = 3 of 'const', returns the boundary value.

check_finite :- To check whether the input arrays contain only finite numbers.

Let's consider the following example:


This is all about Scipy Interpolate Sub-Package and it's properties.