scipy 1.8.0 Pypi GitHub Homepage
Other Docs
MethodsNotesParametersBackRef

Nearest-neighbor interpolation in N > 1 dimensions.

versionadded

Methods

Notes

Uses scipy.spatial.cKDTree

Parameters

x : (Npoints, Ndims) ndarray of floats

Data point coordinates.

y : (Npoints,) ndarray of float or complex

Data values.

rescale : boolean, optional

Rescale points to unit cube before performing interpolation. This is useful if some of the input dimensions have incommensurable units and differ by many orders of magnitude.

versionadded
tree_options : dict, optional

Options passed to the underlying cKDTree .

versionadded

NearestNDInterpolator(x, y).

See Also

CloughTocher2DInterpolator

Piecewise cubic, C1 smooth, curvature-minimizing interpolant in 2D.

LinearNDInterpolator

Piecewise linear interpolant in N dimensions.

griddata

Interpolate unstructured D-D data.

Examples

We can interpolate values on a 2D plane:

>>> from scipy.interpolate import NearestNDInterpolator
... import matplotlib.pyplot as plt
... rng = np.random.default_rng()
... x = rng.random(10) - 0.5
... y = rng.random(10) - 0.5
... z = np.hypot(x, y)
... X = np.linspace(min(x), max(x))
... Y = np.linspace(min(y), max(y))
... X, Y = np.meshgrid(X, Y) # 2D grid for interpolation
... interp = NearestNDInterpolator(list(zip(x, y)), z)
... Z = interp(X, Y)
... plt.pcolormesh(X, Y, Z, shading='auto')
... plt.plot(x, y, "ok", label="input point")
... plt.legend()
... plt.colorbar()
... plt.axis("equal")
... plt.show()
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

scipy.interpolate._interpolate.interpn scipy.interpolate._ndgriddata.griddata scipy.interpolate._interpolate.RegularGridInterpolator scipy.interpolate.interpnd.LinearNDInterpolator scipy.interpolate._rbfinterp.RBFInterpolator scipy.interpolate._ndgriddata.NearestNDInterpolator

Local connectivity graph

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


GitHub : /scipy/interpolate/_ndgriddata.py#20
type: <class 'type'>
Commit: