# cupyx.scipy.interpolate.interpn#

cupyx.scipy.interpolate.interpn(points, values, xi, method='linear', bounds_error=True, fill_value=nan)[source]#

Multidimensional interpolation on regular or rectilinear grids.

Strictly speaking, not all regular grids are supported - this function works on rectilinear grids, that is, a rectangular grid with even or uneven spacing.

Parameters
• points (tuple of cupy.ndarray of float, with shapes (m1, ), ..., (mn, )) – The points defining the regular grid in n dimensions. The points in each dimension (i.e. every elements of the points tuple) must be strictly ascending or descending.

• values (cupy.ndarray of shape (m1, ..., mn, ...)) – The data on the regular grid in n dimensions. Complex data can be acceptable.

• xi (cupy.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”.

• 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.

Returns

values_x – Interpolated values at xi. See notes for behaviour when xi.ndim == 1.

Return type

ndarray, shape xi.shape[:-1] + values.shape[ndim:]

Notes

In the case that xi.ndim == 1 a new axis is inserted into the 0 position of the returned array, values_x, so its shape is instead (1,) + values.shape[ndim:].

If the input data is such that input dimensions have incommensurate units and differ by many orders of magnitude, the interpolant may have numerical artifacts. Consider rescaling the data before interpolation.

Examples

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

>>> import cupy as cp
>>> from cupyx.scipy.interpolate import interpn
>>> def value_func_3d(x, y, z):
...     return 2 * x + 3 * y - z
>>> x = cp.linspace(0, 4, 5)
>>> y = cp.linspace(0, 5, 6)
>>> z = cp.linspace(0, 6, 7)
>>> points = (x, y, z)
>>> values = value_func_3d(*cp.meshgrid(*points, indexing='ij'))

Evaluate the interpolating function at a point

>>> point = cp.array([2.21, 3.12, 1.15])
>>> print(interpn(points, values, point))
[12.63]