cupyx.scipy.interpolate.NearestNDInterpolator#

class cupyx.scipy.interpolate.NearestNDInterpolator(x, y, rescale=False, tree_options=None)[source]#

NearestNDInterpolator(x, y).

Nearest-neighbor interpolator in N > 1 dimensions.

Parameters:
  • x ((npoints, ndims) 2-D ndarray of floats) – Data point coordinates.

  • y ((npoints, ) 1-D 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.

  • tree_options (dict, optional) – Options passed to the underlying cKDTree.

See also

griddata

Interpolate unstructured D-D data.

LinearNDInterpolator

Piecewise linear interpolator in N dimensions.

CloughTocher2DInterpolator

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

interpn

Interpolation on a regular grid or rectilinear grid.

RegularGridInterpolator

Interpolator on a regular or rectilinear grid in arbitrary dimensions (interpn wraps this class).

Notes

Uses cupyx.scipy.spatial.KDTree

Note

For data on a regular grid use interpn instead.

Examples

We can interpolate values on a 2D plane:

>>> from scipy.interpolate import NearestNDInterpolator
>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> rng = cupy.random.default_rng()
>>> x = rng.random(10) - 0.5
>>> y = rng.random(10) - 0.5
>>> z = cupy.hypot(x, y)
>>> X = cupy.linspace(min(x), max(x))
>>> Y = cupy.linspace(min(y), max(y))
>>> X, Y = cupy.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()

Methods

__call__(*args, **query_options)[source]#

Evaluate interpolator at given points.

Parameters:
  • x1 (array-like of float) – Points where to interpolate data at. x1, x2, … xn can be array-like of float with broadcastable shape. or x1 can be array-like of float with shape (..., ndim)

  • x2 (array-like of float) – Points where to interpolate data at. x1, x2, … xn can be array-like of float with broadcastable shape. or x1 can be array-like of float with shape (..., ndim)

  • xn (...) – Points where to interpolate data at. x1, x2, … xn can be array-like of float with broadcastable shape. or x1 can be array-like of float with shape (..., ndim)

  • **query_options

    This allows eps, p and distance_upper_bound being passed to the KDTree’s query function to be explicitly set. See cupyx.scipy.spatial.KDTree.query for an overview of the different options.

    New in version 1.12.0.

__eq__(value, /)#

Return self==value.

__ne__(value, /)#

Return self!=value.

__lt__(value, /)#

Return self<value.

__le__(value, /)#

Return self<=value.

__gt__(value, /)#

Return self>value.

__ge__(value, /)#

Return self>=value.