The data must be defined on a regular grid; the grid spacing however may be uneven. Linear and nearest-neighbor interpolation are supported. After setting up the interpolator object, the interpolation method (linear or nearest) may be chosen at each evaluation.
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.
The points defining the regular grid in n dimensions.
The data on the regular grid in n dimensions.
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".
If True, when interpolated values are requested outside of the domain of the input data, a ValueError is raised. If False, then :None:None:`fill_value`
is used.
If provided, the value to use for points outside of the interpolation domain. If None, values outside the domain are extrapolated.
Interpolation on a regular grid in arbitrary dimensions
LinearNDInterpolator
Piecewise linear interpolant on unstructured data in N dimensions
NearestNDInterpolator
Nearest neighbor interpolation on unstructured data in N dimensions
Evaluate a simple example function on the points of a 3-D 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)
... xg, yg ,zg = np.meshgrid(x, y, z, indexing='ij', sparse=True)
... data = f(xg, yg, zg)
data
is now a 3-D 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)]
.
The following pages refer to to this document either explicitly or contain code examples using this.
scipy.interpolate._interpolate.interpn
scipy.interpolate._interpolate.RegularGridInterpolator
Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.
Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)
SVG is more flexible but power hungry; and does not scale well to 50 + nodes.
All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them