# `interpolate.interpolate`¶

Classes for interpolating values.

## Module Contents¶

### Classes¶

 `interp2d`(self,x,y,z,kind=”linear”,copy=True,bounds_error=False,fill_value=None) interp2d(x, y, z, kind=’linear’, copy=True, bounds_error=False, `interp1d`(self,x,y,kind=”linear”,axis=None,copy=True,bounds_error=None,fill_value=None,assume_sorted=False) Interpolate a 1-D function. `_PPolyBase`(self,c,x,extrapolate=None,axis=0) Base class for piecewise polynomials. `PPoly`() Piecewise polynomial in terms of coefficients and breakpoints `BPoly`() Piecewise polynomial in terms of coefficients and breakpoints. `NdPPoly`(self,c,x,extrapolate=None) Piecewise tensor product polynomial `RegularGridInterpolator`(self,points,values,method=”linear”,bounds_error=True,fill_value=None) Interpolation on a regular grid in arbitrary dimensions `_ppform`(self,coeffs,breaks,fill=0.0,sort=False) Deprecated piecewise polynomial class.

### Functions¶

 `prod`(x) Product of a list of numbers; ~40x faster vs np.prod for Python tuples `lagrange`(x,w) r `_check_broadcast_up_to`(arr_from,shape_to,name) Helper to check that arr_from broadcasts up to shape_to `_do_extrapolate`(fill_value) Helper to check if fill_value == “extrapolate” without warnings `interpn`(points,values,xi,method=”linear”,bounds_error=True,fill_value=None) Multidimensional interpolation on regular grids. `_dot0`(a,b) Similar to numpy.dot, but sum over last axis of a and 1st axis of b `_find_smoothest`(xk,yk,order,conds=None,B=None) `_find_user`(xk,yk,order,conds,B) `splmake`(xk,yk,order=3,kind=”smoothest”,conds=None) Return a representation of a spline given data-points at internal knots `spleval`(xck,xnew,deriv=0) Evaluate a fixed spline represented by the given tuple at the new x-values `spltopp`(xk,cvals,k) Return a piece-wise polynomial object from a fixed-spline tuple. `spline`(xk,yk,xnew,order=3,kind=”smoothest”,conds=None) Interpolate a curve at new points using a spline fit
`prod`(x)

Product of a list of numbers; ~40x faster vs np.prod for Python tuples

`lagrange`(x, w)

r Return a Lagrange interpolating polynomial.

Given two 1-D arrays x and w, returns the Lagrange interpolating polynomial through the points `(x, w)`.

Warning: This implementation is numerically unstable. Do not expect to be able to use more than about 20 points even if they are chosen optimally.

x : array_like
x represents the x-coordinates of a set of datapoints.
w : array_like
w represents the y-coordinates of a set of datapoints, i.e. f(x).
lagrange : numpy.poly1d instance
The Lagrange interpolating polynomial.

Interpolate by 3 points.

```>>> from scipy.interpolate import lagrange
>>> x = np.array([0, 1, 2])
>>> y = x**3
>>> poly = lagrange(x, y)
```

Since there are only 3 points, Lagrange polynomial has degree 2. Explicitly, it is given by

```>>> from numpy.polynomial.polynomial import Polynomial
>>> Polynomial(poly).coef
array([ 3., -2.,  0.])
```
class `interp2d`(x, y, z, kind="linear", copy=True, bounds_error=False, fill_value=None)
interp2d(x, y, z, kind=’linear’, copy=True, bounds_error=False,
fill_value=nan)

Interpolate over a 2-D grid.

x, y and z are arrays of values used to approximate some function f: `z = f(x, y)`. This class returns a function whose call method uses spline interpolation to find the value of new points.

If x and y represent a regular grid, consider using RectBivariateSpline.

Note that calling interp2d with NaNs present in input values results in undefined behaviour.

__call__

x, y : array_like

Arrays defining the data point coordinates.

If the points lie on a regular grid, x can specify the column coordinates and y the row coordinates, for example:

```>>> x = [0,1,2];  y = [0,3]; z = [[1,2,3], [4,5,6]]
```

Otherwise, x and y must specify the full coordinates for each point, for example:

```>>> x = [0,1,2,0,1,2];  y = [0,0,0,3,3,3]; z = [1,2,3,4,5,6]
```

If x and y are multi-dimensional, they are flattened before use.

z : array_like
The values of the function to interpolate at the data points. If z is a multi-dimensional array, it is flattened before use. The length of a flattened z array is either len(x)*len(y) if x and y specify the column and row coordinates or `len(z) == len(x) == len(y)` if x and y specify coordinates for each point.
kind : {‘linear’, ‘cubic’, ‘quintic’}, optional
The kind of spline interpolation to use. Default is ‘linear’.
copy : bool, optional
If True, the class makes internal copies of x, y and z. If False, references may be used. The default is to copy.
bounds_error : bool, optional
If True, when interpolated values are requested outside of the domain of the input data (x,y), a ValueError is raised. If False, then fill_value is used.
fill_value : number, optional
If provided, the value to use for points outside of the interpolation domain. If omitted (None), values outside the domain are extrapolated.
RectBivariateSpline :
Much faster 2D interpolation if your input data is on a grid
bisplrep, bisplev :
Spline interpolation based on FITPACK

BivariateSpline : a more recent wrapper of the FITPACK routines interp1d : one dimension version of this function

The minimum number of data points required along the interpolation axis is `(k+1)**2`, with k=1 for linear, k=3 for cubic and k=5 for quintic interpolation.

The interpolator is constructed by bisplrep, with a smoothing factor of 0. If more control over smoothing is needed, bisplrep should be used directly.

Construct a 2-D grid and interpolate on it:

```>>> from scipy import interpolate
>>> x = np.arange(-5.01, 5.01, 0.25)
>>> y = np.arange(-5.01, 5.01, 0.25)
>>> xx, yy = np.meshgrid(x, y)
>>> z = np.sin(xx**2+yy**2)
>>> f = interpolate.interp2d(x, y, z, kind='cubic')
```

Now use the obtained interpolation function and plot the result:

```>>> import matplotlib.pyplot as plt
>>> xnew = np.arange(-5.01, 5.01, 1e-2)
>>> ynew = np.arange(-5.01, 5.01, 1e-2)
>>> znew = f(xnew, ynew)
>>> plt.plot(x, z[0, :], 'ro-', xnew, znew[0, :], 'b-')
>>> plt.show()
```
`__init__`(x, y, z, kind="linear", copy=True, bounds_error=False, fill_value=None)
`__call__`(x, y, dx=0, dy=0, assume_sorted=False)

Interpolate the function.

x : 1D array
x-coordinates of the mesh on which to interpolate.
y : 1D array
y-coordinates of the mesh on which to interpolate.
dx : int >= 0, < kx
Order of partial derivatives in x.
dy : int >= 0, < ky
Order of partial derivatives in y.
assume_sorted : bool, optional
If False, values of x and y can be in any order and they are sorted first. If True, x and y have to be arrays of monotonically increasing values.
z : 2D array with shape (len(y), len(x))
The interpolated values.
`_check_broadcast_up_to`(arr_from, shape_to, name)

Helper to check that arr_from broadcasts up to shape_to

`_do_extrapolate`(fill_value)

Helper to check if fill_value == “extrapolate” without warnings

class `interp1d`(x, y, kind="linear", axis=None, copy=True, bounds_error=None, fill_value=None, assume_sorted=False)

Interpolate a 1-D function.

x and y are arrays of values used to approximate some function f: `y = f(x)`. This class returns a function whose call method uses interpolation to find the value of new points.

Note that calling interp1d with NaNs present in input values results in undefined behaviour.

x : (N,) array_like
A 1-D array of real values.
y : (…,N,…) array_like
A N-D array of real values. The length of y along the interpolation axis must be equal to the length of x.
kind : str or int, optional
Specifies the kind of interpolation as a string (‘linear’, ‘nearest’, ‘zero’, ‘slinear’, ‘quadratic’, ‘cubic’ where ‘zero’, ‘slinear’, ‘quadratic’ and ‘cubic’ refer to a spline interpolation of zeroth, first, second or third order) or as an integer specifying the order of the spline interpolator to use. Default is ‘linear’.
axis : int, optional
Specifies the axis of y along which to interpolate. Interpolation defaults to the last axis of y.
copy : bool, optional
If True, the class makes internal copies of x and y. If False, references to x and y are used. The default is to copy.
bounds_error : bool, optional
If True, a ValueError is raised any time interpolation is attempted on a value outside of the range of x (where extrapolation is necessary). If False, out of bounds values are assigned fill_value. By default, an error is raised unless fill_value=”extrapolate”.
fill_value : array-like or (array-like, array_like) or “extrapolate”, optional
• if a ndarray (or float), this value will be used to fill in for requested points outside of the data range. If not provided, then the default is NaN. The array-like must broadcast properly to the dimensions of the non-interpolation axes.

• If a two-element tuple, then the first element is used as a fill value for `x_new < x[0]` and the second element is used for `x_new > x[-1]`. Anything that is not a 2-element tuple (e.g., list or ndarray, regardless of shape) is taken to be a single array-like argument meant to be used for both bounds as `below, above = fill_value, fill_value`.

New in version 0.17.0.

• If “extrapolate”, then points outside the data range will be extrapolated.

New in version 0.17.0.

assume_sorted : bool, optional
If False, values of x can be in any order and they are sorted first. If True, x has to be an array of monotonically increasing values.

__call__

splrep, splev
Spline interpolation/smoothing based on FITPACK.

UnivariateSpline : An object-oriented wrapper of the FITPACK routines. interp2d : 2-D interpolation

```>>> import matplotlib.pyplot as plt
>>> from scipy import interpolate
>>> x = np.arange(0, 10)
>>> y = np.exp(-x/3.0)
>>> f = interpolate.interp1d(x, y)
```
```>>> xnew = np.arange(0, 9, 0.1)
>>> ynew = f(xnew)   # use interpolation function returned by `interp1d`
>>> plt.plot(x, y, 'o', xnew, ynew, '-')
>>> plt.show()
```
`__init__`(x, y, kind="linear", axis=None, copy=True, bounds_error=None, fill_value=None, assume_sorted=False)

Initialize a 1D linear interpolation class.

`fill_value`()
`fill_value`(fill_value)
`_call_linear_np`(x_new)
`_call_linear`(x_new)
`_call_nearest`(x_new)

Find nearest neighbour interpolated y_new = f(x_new).

`_call_spline`(x_new)
`_call_nan_spline`(x_new)
`_evaluate`(x_new)
`_check_bounds`(x_new)

Check the inputs for being in the bounds of the interpolated data.

x_new : array

out_of_bounds : bool array
The mask on x_new of values that are out of the bounds.
class `_PPolyBase`(c, x, extrapolate=None, axis=0)

Base class for piecewise polynomials.

`__init__`(c, x, extrapolate=None, axis=0)
`_get_dtype`(dtype)
`construct_fast`(c, x, extrapolate=None, axis=0)

Construct the piecewise polynomial without making checks.

Takes the same parameters as the constructor. Input arguments c and x must be arrays of the correct shape and type. The c array can only be of dtypes float and complex, and x array must have dtype float.

`_ensure_c_contiguous`()

c and x may be modified by the user. The Cython code expects that they are C contiguous.

`extend`(c, x, right=None)

Add additional breakpoints and coefficients to the polynomial.

c : ndarray, size (k, m, …)
Additional coefficients for polynomials in intervals. Note that the first additional interval will be formed using one of the self.x end points.
x : ndarray, size (m,)
Additional breakpoints. Must be sorted in the same order as self.x and either to the right or to the left of the current breakpoints.
right

Deprecated argument. Has no effect.

Deprecated since version 0.19.

`__call__`(x, nu=0, extrapolate=None)

Evaluate the piecewise polynomial or its derivative.

x : array_like
Points to evaluate the interpolant at.
nu : int, optional
Order of derivative to evaluate. Must be non-negative.
extrapolate : {bool, ‘periodic’, None}, optional
If bool, determines whether to extrapolate to out-of-bounds points based on first and last intervals, or to return NaNs. If ‘periodic’, periodic extrapolation is used. If None (default), use self.extrapolate.
y : array_like
Interpolated values. Shape is determined by replacing the interpolation axis in the original array with the shape of x.

Derivatives are evaluated piecewise for each polynomial segment, even if the polynomial is not differentiable at the breakpoints. The polynomial intervals are considered half-open, `[a, b)`, except for the last interval which is closed `[a, b]`.

class `PPoly`

Piecewise polynomial in terms of coefficients and breakpoints

The polynomial between `x[i]` and `x[i + 1]` is written in the local power basis:

```S = sum(c[m, i] * (xp - x[i])**(k-m) for m in range(k+1))
```

where `k` is the degree of the polynomial.

c : ndarray, shape (k, m, …)
Polynomial coefficients, order k and m intervals
x : ndarray, shape (m+1,)
Polynomial breakpoints. Must be sorted in either increasing or decreasing order.
extrapolate : bool or ‘periodic’, optional
If bool, determines whether to extrapolate to out-of-bounds points based on first and last intervals, or to return NaNs. If ‘periodic’, periodic extrapolation is used. Default is True.
axis : int, optional
Interpolation axis. Default is zero.
x : ndarray
Breakpoints.
c : ndarray
Coefficients of the polynomials. They are reshaped to a 3-dimensional array with the last dimension representing the trailing dimensions of the original coefficient array.
axis : int
Interpolation axis.

__call__ derivative antiderivative integrate solve roots extend from_spline from_bernstein_basis construct_fast

BPoly : piecewise polynomials in the Bernstein basis

High-order polynomials in the power basis can be numerically unstable. Precision problems can start to appear for orders larger than 20-30.

`_evaluate`(x, nu, extrapolate, out)
`derivative`(nu=1)

Construct a new piecewise polynomial representing the derivative.

nu : int, optional
Order of derivative to evaluate. Default is 1, i.e. compute the first derivative. If negative, the antiderivative is returned.
pp : PPoly
Piecewise polynomial of order k2 = k - n representing the derivative of this polynomial.

Derivatives are evaluated piecewise for each polynomial segment, even if the polynomial is not differentiable at the breakpoints. The polynomial intervals are considered half-open, `[a, b)`, except for the last interval which is closed `[a, b]`.

`antiderivative`(nu=1)

Construct a new piecewise polynomial representing the antiderivative.

Antiderivative is also the indefinite integral of the function, and derivative is its inverse operation.

nu : int, optional
Order of antiderivative to evaluate. Default is 1, i.e. compute the first integral. If negative, the derivative is returned.
pp : PPoly
Piecewise polynomial of order k2 = k + n representing the antiderivative of this polynomial.

The antiderivative returned by this function is continuous and continuously differentiable to order n-1, up to floating point rounding error.

If antiderivative is computed and `self.extrapolate='periodic'`, it will be set to False for the returned instance. This is done because the antiderivative is no longer periodic and its correct evaluation outside of the initially given x interval is difficult.

`integrate`(a, b, extrapolate=None)

Compute a definite integral over a piecewise polynomial.

a : float
Lower integration bound
b : float
Upper integration bound
extrapolate : {bool, ‘periodic’, None}, optional
If bool, determines whether to extrapolate to out-of-bounds points based on first and last intervals, or to return NaNs. If ‘periodic’, periodic extrapolation is used. If None (default), use self.extrapolate.
ig : array_like
Definite integral of the piecewise polynomial over [a, b]
`solve`(y=0.0, discontinuity=True, extrapolate=None)

Find real solutions of the the equation `pp(x) == y`.

y : float, optional
Right-hand side. Default is zero.
discontinuity : bool, optional
Whether to report sign changes across discontinuities at breakpoints as roots.
extrapolate : {bool, ‘periodic’, None}, optional
If bool, determines whether to return roots from the polynomial extrapolated based on first and last intervals, ‘periodic’ works the same as False. If None (default), use self.extrapolate.
roots : ndarray

Roots of the polynomial(s).

If the PPoly object describes multiple polynomials, the return value is an object array whose each element is an ndarray containing the roots.

This routine works only on real-valued polynomials.

If the piecewise polynomial contains sections that are identically zero, the root list will contain the start point of the corresponding interval, followed by a `nan` value.

If the polynomial is discontinuous across a breakpoint, and there is a sign change across the breakpoint, this is reported if the discont parameter is True.

Finding roots of `[x**2 - 1, (x - 1)**2]` defined on intervals `[-2, 1], [1, 2]`:

```>>> from scipy.interpolate import PPoly
>>> pp = PPoly(np.array([[1, -4, 3], [1, 0, 0]]).T, [-2, 1, 2])
>>> pp.roots()
array([-1.,  1.])
```
`roots`(discontinuity=True, extrapolate=None)

Find real roots of the the piecewise polynomial.

discontinuity : bool, optional
Whether to report sign changes across discontinuities at breakpoints as roots.
extrapolate : {bool, ‘periodic’, None}, optional
If bool, determines whether to return roots from the polynomial extrapolated based on first and last intervals, ‘periodic’ works the same as False. If None (default), use self.extrapolate.
roots : ndarray

Roots of the polynomial(s).

If the PPoly object describes multiple polynomials, the return value is an object array whose each element is an ndarray containing the roots.

PPoly.solve

`from_spline`(tck, extrapolate=None)

Construct a piecewise polynomial from a spline

tck
A spline, as returned by splrep or a BSpline object.
extrapolate : bool or ‘periodic’, optional
If bool, determines whether to extrapolate to out-of-bounds points based on first and last intervals, or to return NaNs. If ‘periodic’, periodic extrapolation is used. Default is True.
`from_bernstein_basis`(bp, extrapolate=None)

Construct a piecewise polynomial in the power basis from a polynomial in Bernstein basis.

bp : BPoly
A Bernstein basis polynomial, as created by BPoly
extrapolate : bool or ‘periodic’, optional
If bool, determines whether to extrapolate to out-of-bounds points based on first and last intervals, or to return NaNs. If ‘periodic’, periodic extrapolation is used. Default is True.
class `BPoly`

Piecewise polynomial in terms of coefficients and breakpoints.

The polynomial between `x[i]` and `x[i + 1]` is written in the Bernstein polynomial basis:

```S = sum(c[a, i] * b(a, k; x) for a in range(k+1)),
```

where `k` is the degree of the polynomial, and:

```b(a, k; x) = binom(k, a) * t**a * (1 - t)**(k - a),
```

with `t = (x - x[i]) / (x[i+1] - x[i])` and `binom` is the binomial coefficient.

c : ndarray, shape (k, m, …)
Polynomial coefficients, order k and m intervals
x : ndarray, shape (m+1,)
Polynomial breakpoints. Must be sorted in either increasing or decreasing order.
extrapolate : bool, optional
If bool, determines whether to extrapolate to out-of-bounds points based on first and last intervals, or to return NaNs. If ‘periodic’, periodic extrapolation is used. Default is True.
axis : int, optional
Interpolation axis. Default is zero.
x : ndarray
Breakpoints.
c : ndarray
Coefficients of the polynomials. They are reshaped to a 3-dimensional array with the last dimension representing the trailing dimensions of the original coefficient array.
axis : int
Interpolation axis.

__call__ extend derivative antiderivative integrate construct_fast from_power_basis from_derivatives

PPoly : piecewise polynomials in the power basis

Properties of Bernstein polynomials are well documented in the literature. Here’s a non-exhaustive list:

 [2] Kenneth I. Joy, Bernstein polynomials, http://www.idav.ucdavis.edu/education/CAGDNotes/Bernstein-Polynomials.pdf
 [3] E. H. Doha, A. H. Bhrawy, and M. A. Saker, Boundary Value Problems, vol 2011, article ID 829546, :doi:`10.1155/2011/829543`.
```>>> from scipy.interpolate import BPoly
>>> x = [0, 1]
>>> c = [[1], [2], [3]]
>>> bp = BPoly(c, x)
```

This creates a 2nd order polynomial

`_evaluate`(x, nu, extrapolate, out)
`derivative`(nu=1)

Construct a new piecewise polynomial representing the derivative.

nu : int, optional
Order of derivative to evaluate. Default is 1, i.e. compute the first derivative. If negative, the antiderivative is returned.
bp : BPoly
Piecewise polynomial of order k - nu representing the derivative of this polynomial.
`antiderivative`(nu=1)

Construct a new piecewise polynomial representing the antiderivative.

nu : int, optional
Order of antiderivative to evaluate. Default is 1, i.e. compute the first integral. If negative, the derivative is returned.
bp : BPoly
Piecewise polynomial of order k + nu representing the antiderivative of this polynomial.

If antiderivative is computed and `self.extrapolate='periodic'`, it will be set to False for the returned instance. This is done because the antiderivative is no longer periodic and its correct evaluation outside of the initially given x interval is difficult.

`integrate`(a, b, extrapolate=None)

Compute a definite integral over a piecewise polynomial.

a : float
Lower integration bound
b : float
Upper integration bound
extrapolate : {bool, ‘periodic’, None}, optional
Whether to extrapolate to out-of-bounds points based on first and last intervals, or to return NaNs. If ‘periodic’, periodic extrapolation is used. If None (default), use self.extrapolate.
array_like
Definite integral of the piecewise polynomial over [a, b]
`extend`(c, x, right=None)
`from_power_basis`(pp, extrapolate=None)

Construct a piecewise polynomial in Bernstein basis from a power basis polynomial.

pp : PPoly
A piecewise polynomial in the power basis
extrapolate : bool or ‘periodic’, optional
If bool, determines whether to extrapolate to out-of-bounds points based on first and last intervals, or to return NaNs. If ‘periodic’, periodic extrapolation is used. Default is True.
`from_derivatives`(xi, yi, orders=None, extrapolate=None)

Construct a piecewise polynomial in the Bernstein basis, compatible with the specified values and derivatives at breakpoints.

xi : array_like
sorted 1D array of x-coordinates
yi : array_like or list of array_likes
`yi[i][j]` is the `j`-th derivative known at `xi[i]`
orders : None or int or array_like of ints. Default: None.
Specifies the degree of local polynomials. If not None, some derivatives are ignored.
extrapolate : bool or ‘periodic’, optional
If bool, determines whether to extrapolate to out-of-bounds points based on first and last intervals, or to return NaNs. If ‘periodic’, periodic extrapolation is used. Default is True.

If `k` derivatives are specified at a breakpoint `x`, the constructed polynomial is exactly `k` times continuously differentiable at `x`, unless the `order` is provided explicitly. In the latter case, the smoothness of the polynomial at the breakpoint is controlled by the `order`.

Deduces the number of derivatives to match at each end from `order` and the number of derivatives available. If possible it uses the same number of derivatives from each end; if the number is odd it tries to take the extra one from y2. In any case if not enough derivatives are available at one end or another it draws enough to make up the total from the other end.

If the order is too high and not enough derivatives are available, an exception is raised.

```>>> from scipy.interpolate import BPoly
>>> BPoly.from_derivatives([0, 1], [[1, 2], [3, 4]])
```

Creates a polynomial f(x) of degree 3, defined on [0, 1] such that f(0) = 1, df/dx(0) = 2, f(1) = 3, df/dx(1) = 4

```>>> BPoly.from_derivatives([0, 1, 2], [[0, 1], [0], [2]])
```

Creates a piecewise polynomial f(x), such that f(0) = f(1) = 0, f(2) = 2, and df/dx(0) = 1. Based on the number of derivatives provided, the order of the local polynomials is 2 on [0, 1] and 1 on [1, 2]. Notice that no restriction is imposed on the derivatives at x = 1 and x = 2.

Indeed, the explicit form of the polynomial is:

```f(x) = | x * (1 - x),  0 <= x < 1
| 2 * (x - 1),  1 <= x <= 2
```

So that f’(1-0) = -1 and f’(1+0) = 2

`_construct_from_derivatives`(xb, ya, yb)

rCompute the coefficients of a polynomial in the Bernstein basis given the values and derivatives at the edges.

Return the coefficients of a polynomial in the Bernstein basis defined on [xa, xb] and having the values and derivatives at the endpoints `xa` and `xb` as specified by `ya` and `yb`. The polynomial constructed is of the minimal possible degree, i.e., if the lengths of `ya` and `yb` are `na` and `nb`, the degree of the polynomial is `na + nb - 1`.

xa : float
Left-hand end point of the interval
xb : float
Right-hand end point of the interval
ya : array_like
Derivatives at `xa`. `ya[0]` is the value of the function, and `ya[i]` for `i > 0` is the value of the `i`-th derivative.
yb : array_like
Derivatives at `xb`.
array
coefficient array of a polynomial having specified derivatives

This uses several facts from life of Bernstein basis functions. First of all,

If B(x) is a linear combination of the form

then :math: B’(x) = n sum_{a=0}^{n-1} (c_{a+1} - c_{a}) b_{a, n-1}. Iterating the latter one, one finds for the q-th derivative

with

This way, only a=0 contributes to :math: B^{q}(x = xa), and c_q are found one by one by iterating q = 0, …, na.

At x = xb it’s the same with a = n - q.

`_raise_degree`(d)

rRaise a degree of a polynomial in the Bernstein basis.

Given the coefficients of a polynomial degree k, return (the coefficients of) the equivalent polynomial of degree k+d.

c : array_like
coefficient array, 1D

d : integer

array
coefficient array, 1D array of length c.shape[0] + d

This uses the fact that a Bernstein polynomial b_{a, k} can be identically represented as a linear combination of polynomials of a higher degree k+d:

class `NdPPoly`(c, x, extrapolate=None)

Piecewise tensor product polynomial

The value at point xp = (x’, y’, z’, …) is evaluated by first computing the interval indices i such that:

```x[0][i[0]] <= x' < x[0][i[0]+1]
x[1][i[1]] <= y' < x[1][i[1]+1]
...
```

and then computing:

```S = sum(c[k0-m0-1,...,kn-mn-1,i[0],...,i[n]]
* (xp[0] - x[0][i[0]])**m0
* ...
* (xp[n] - x[n][i[n]])**mn
for m0 in range(k[0]+1)
...
for mn in range(k[n]+1))
```

where `k[j]` is the degree of the polynomial in dimension j. This representation is the piecewise multivariate power basis.

c : ndarray, shape (k0, …, kn, m0, …, mn, …)
Polynomial coefficients, with polynomial order kj and mj+1 intervals for each dimension j.
x : ndim-tuple of ndarrays, shapes (mj+1,)
Polynomial breakpoints for each dimension. These must be sorted in increasing order.
extrapolate : bool, optional
Whether to extrapolate to out-of-bounds points based on first and last intervals, or to return NaNs. Default: True.
x : tuple of ndarrays
Breakpoints.
c : ndarray
Coefficients of the polynomials.

__call__ construct_fast

PPoly : piecewise polynomials in 1D

High-order polynomials in the power basis can be numerically unstable.

`__init__`(c, x, extrapolate=None)
`construct_fast`(c, x, extrapolate=None)

Construct the piecewise polynomial without making checks.

Takes the same parameters as the constructor. Input arguments c and x must be arrays of the correct shape and type. The c array can only be of dtypes float and complex, and x array must have dtype float.

`_get_dtype`(dtype)
`_ensure_c_contiguous`()
`__call__`(x, nu=None, extrapolate=None)

Evaluate the piecewise polynomial or its derivative

x : array-like
Points to evaluate the interpolant at.
nu : tuple, optional
Orders of derivatives to evaluate. Each must be non-negative.
extrapolate : bool, optional
Whether to extrapolate to out-of-bounds points based on first and last intervals, or to return NaNs.
y : array-like
Interpolated values. Shape is determined by replacing the interpolation axis in the original array with the shape of x.

Derivatives are evaluated piecewise for each polynomial segment, even if the polynomial is not differentiable at the breakpoints. The polynomial intervals are considered half-open, `[a, b)`, except for the last interval which is closed `[a, b]`.

`_derivative_inplace`(nu, axis)

Compute 1D derivative along a selected dimension in-place May result to non-contiguous c array.

`_antiderivative_inplace`(nu, axis)

Compute 1D antiderivative along a selected dimension May result to non-contiguous c array.

`derivative`(nu)

Construct a new piecewise polynomial representing the derivative.

nu : ndim-tuple of int
Order of derivatives to evaluate for each dimension. If negative, the antiderivative is returned.
pp : NdPPoly
Piecewise polynomial of orders (k[0] - nu[0], …, k[n] - nu[n]) representing the derivative of this polynomial.

Derivatives are evaluated piecewise for each polynomial segment, even if the polynomial is not differentiable at the breakpoints. The polynomial intervals in each dimension are considered half-open, `[a, b)`, except for the last interval which is closed `[a, b]`.

`antiderivative`(nu)

Construct a new piecewise polynomial representing the antiderivative.

Antiderivative is also the indefinite integral of the function, and derivative is its inverse operation.

nu : ndim-tuple of int
Order of derivatives to evaluate for each dimension. If negative, the derivative is returned.
pp : PPoly
Piecewise polynomial of order k2 = k + n representing the antiderivative of this polynomial.

The antiderivative returned by this function is continuous and continuously differentiable to order n-1, up to floating point rounding error.

`integrate_1d`(a, b, axis, extrapolate=None)

r Compute NdPPoly representation for one dimensional definite integral

The result is a piecewise polynomial representing the integral:

where the dimension integrated over is specified with the axis parameter.

a, b : float
Lower and upper bound for integration.
axis : int
Dimension over which to compute the 1D integrals
extrapolate : bool, optional
Whether to extrapolate to out-of-bounds points based on first and last intervals, or to return NaNs.
ig : NdPPoly or array-like
Definite integral of the piecewise polynomial over [a, b]. If the polynomial was 1-dimensional, an array is returned, otherwise, an NdPPoly object.
`integrate`(ranges, extrapolate=None)

Compute a definite integral over a piecewise polynomial.

ranges : ndim-tuple of 2-tuples float
Sequence of lower and upper bounds for each dimension, `[(a[0], b[0]), ..., (a[ndim-1], b[ndim-1])]`
extrapolate : bool, optional
Whether to extrapolate to out-of-bounds points based on first and last intervals, or to return NaNs.
ig : array_like
Definite integral of the piecewise polynomial over [a[0], b[0]] x … x [a[ndim-1], b[ndim-1]]
class `RegularGridInterpolator`(points, values, method="linear", bounds_error=True, fill_value=None)

Interpolation on a regular grid in arbitrary dimensions

The data must be defined on a regular grid; the grid spacing however may be uneven. Linear and nearest-neighbour interpolation are supported. After setting up the interpolator object, the interpolation method (linear or nearest) may be chosen at each evaluation.

points : tuple of ndarray of float, with shapes (m1, ), …, (mn, )
The points defining the regular grid in n dimensions.
values : array_like, shape (m1, …, mn, …)
The data on the regular grid in n dimensions.
method : str, optional
The method of interpolation to perform. Supported are “linear” and “nearest”. This parameter will become the default for the object’s `__call__` method. Default is “linear”.
bounds_error : bool, optional
If True, when interpolated values are requested outside of the domain of the input data, a ValueError is raised. If False, then fill_value is used.
fill_value : number, optional
If provided, the value to use for points outside of the interpolation domain. If None, values outside the domain are extrapolated.

__call__

Contrary to LinearNDInterpolator and NearestNDInterpolator, this class avoids expensive triangulation of the input data by taking advantage of the regular grid structure.

If any of points have a dimension of size 1, linear interpolation will return an array of nan values. Nearest-neighbor interpolation will work as usual in this case.

New in version 0.14.

Evaluate a simple example function on the points of a 3D grid:

```>>> from scipy.interpolate import RegularGridInterpolator
>>> def f(x, y, z):
...     return 2 * x**3 + 3 * y**2 - z
>>> x = np.linspace(1, 4, 11)
>>> y = np.linspace(4, 7, 22)
>>> z = np.linspace(7, 9, 33)
>>> data = f(*np.meshgrid(x, y, z, indexing='ij', sparse=True))
```

`data` is now a 3D array with `data[i,j,k] = f(x[i], y[j], z[k])`. Next, define an interpolating function from this data:

```>>> my_interpolating_function = RegularGridInterpolator((x, y, z), data)
```

Evaluate the interpolating function at the two points `(x,y,z) = (2.1, 6.2, 8.3)` and `(3.3, 5.2, 7.1)`:

```>>> pts = np.array([[2.1, 6.2, 8.3], [3.3, 5.2, 7.1]])
>>> my_interpolating_function(pts)
array([ 125.80469388,  146.30069388])
```

which is indeed a close approximation to `[f(2.1, 6.2, 8.3), f(3.3, 5.2, 7.1)]`.

NearestNDInterpolator : Nearest neighbour interpolation on unstructured
data in N dimensions
LinearNDInterpolator : Piecewise linear interpolant on unstructured data
in N dimensions
 [1] Python package regulargrid by Johannes Buchner, see https://pypi.python.org/pypi/regulargrid/
 [2] Trilinear interpolation. (2013, January 17). In Wikipedia, The Free Encyclopedia. Retrieved 27 Feb 2013 01:28. http://en.wikipedia.org/w/index.php?title=Trilinear_interpolation&oldid=533448871
 [3] Weiser, Alan, and Sergio E. Zarantonello. “A note on piecewise linear and multilinear table interpolation in many dimensions.” MATH. COMPUT. 50.181 (1988): 189-196. http://www.ams.org/journals/mcom/1988-50-181/S0025-5718-1988-0917826-0/S0025-5718-1988-0917826-0.pdf
`__init__`(points, values, method="linear", bounds_error=True, fill_value=None)
`__call__`(xi, method=None)

Interpolation at coordinates

xi : ndarray of shape (…, ndim)
The coordinates to sample the gridded data at
method : str
The method of interpolation to perform. Supported are “linear” and “nearest”.
`_evaluate_linear`(indices, norm_distances, out_of_bounds)
`_evaluate_nearest`(indices, norm_distances, out_of_bounds)
`_find_indices`(xi)
`interpn`(points, values, xi, method="linear", bounds_error=True, fill_value=None)

Multidimensional interpolation on regular grids.

points : tuple of ndarray of float, with shapes (m1, ), …, (mn, )
The points defining the regular grid in n dimensions.
values : array_like, shape (m1, …, mn, …)
The data on the regular grid in n dimensions.
xi : ndarray of shape (…, ndim)
The coordinates to sample the gridded data at
method : str, optional
The method of interpolation to perform. Supported are “linear” and “nearest”, and “splinef2d”. “splinef2d” is only supported for 2-dimensional data.
bounds_error : bool, optional
If True, when interpolated values are requested outside of the domain of the input data, a ValueError is raised. If False, then fill_value is used.
fill_value : number, optional
If provided, the value to use for points outside of the interpolation domain. If None, values outside the domain are extrapolated. Extrapolation is not supported by method “splinef2d”.
values_x : ndarray, shape xi.shape[:-1] + values.shape[ndim:]
Interpolated values at input coordinates.

New in version 0.14.

NearestNDInterpolator : Nearest neighbour interpolation on unstructured
data in N dimensions
LinearNDInterpolator : Piecewise linear interpolant on unstructured data
in N dimensions
RegularGridInterpolator : Linear and nearest-neighbor Interpolation on a
regular grid in arbitrary dimensions

RectBivariateSpline : Bivariate spline approximation over a rectangular mesh

class `_ppform`(coeffs, breaks, fill=0.0, sort=False)

Deprecated piecewise polynomial class.

New code should use the PPoly class instead.

`__init__`(coeffs, breaks, fill=0.0, sort=False)
`__call__`(x)
`_evaluate`(x, nu, extrapolate, out)
`fromspline`(xk, cvals, order, fill=0.0)
`_dot0`(a, b)

Similar to numpy.dot, but sum over last axis of a and 1st axis of b

`_find_smoothest`(xk, yk, order, conds=None, B=None)
`_find_user`(xk, yk, order, conds, B)
`splmake`(xk, yk, order=3, kind="smoothest", conds=None)

Return a representation of a spline given data-points at internal knots

xk : array_like
The input array of x values of rank 1
yk : array_like
The input array of y values of rank N. yk can be an N-d array to represent more than one curve, through the same xk points. The first dimension is assumed to be the interpolating dimension and is the same length of xk.
order : int, optional
Order of the spline
kind : str, optional
Can be ‘smoothest’, ‘not_a_knot’, ‘fixed’, ‘clamped’, ‘natural’, ‘periodic’, ‘symmetric’, ‘user’, ‘mixed’ and it is ignored if order < 2
conds : optional
Conds
splmake : tuple
Return a (xk, cvals, k) representation of a spline given data-points where the (internal) knots are at the data-points.
`spleval`(xck, xnew, deriv=0)

Evaluate a fixed spline represented by the given tuple at the new x-values

The xj values are the interior knot points. The approximation region is xj[0] to xj[-1]. If N+1 is the length of xj, then cvals should have length N+k where k is the order of the spline.

(xj, cvals, k) : tuple
Parameters that define the fixed spline
xj : array_like
Interior knot points
cvals : array_like
Curvature
k : int
Order of the spline
xnew : array_like
Locations to calculate spline
deriv : int
Deriv
spleval : ndarray
If cvals represents more than one curve (cvals.ndim > 1) and/or xnew is N-d, then the result is xnew.shape + cvals.shape[1:] providing the interpolation of multiple curves.

Internally, an additional k-1 knot points are added on either side of the spline.

`spltopp`(xk, cvals, k)

Return a piece-wise polynomial object from a fixed-spline tuple.

`spline`(xk, yk, xnew, order=3, kind="smoothest", conds=None)

Interpolate a curve at new points using a spline fit

xk, yk : array_like
The x and y values that define the curve.
xnew : array_like
The x values where spline should estimate the y values.
order : int
Default is 3.
kind : string
One of {‘smoothest’}
conds : Don’t know
Don’t know
spline : ndarray
An array of y values; the spline evaluated at the positions xnew.