scipy.interpolate.RegularGridInterpolator.

__call__#

RegularGridInterpolator.__call__(xi, method=None, *, nu=None)[source]#

Interpolation at coordinates.

Parameters:
xindarray of shape (…, ndim)

The coordinates to evaluate the interpolator at.

methodstr, optional

The method of interpolation to perform. Supported are “linear”, “nearest”, “slinear”, “cubic”, “quintic” and “pchip”. Default is the method chosen when the interpolator was created.

nusequence of ints, length ndim, optional

If not None, the orders of the derivatives to evaluate. Each entry must be non-negative. Only allowed for methods “slinear”, “cubic” and “quintic”.

Added in version 1.13.

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

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

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:].

Examples

Here we define a nearest-neighbor interpolator of a simple function

>>> import numpy as np
>>> x, y = np.array([0, 1, 2]), np.array([1, 3, 7])
>>> def f(x, y):
...     return x**2 + y**2
>>> data = f(*np.meshgrid(x, y, indexing='ij', sparse=True))
>>> from scipy.interpolate import RegularGridInterpolator
>>> interp = RegularGridInterpolator((x, y), data, method='nearest')

By construction, the interpolator uses the nearest-neighbor interpolation

>>> interp([[1.5, 1.3], [0.3, 4.5]])
array([2., 9.])

We can however evaluate the linear interpolant by overriding the method parameter

>>> interp([[1.5, 1.3], [0.3, 4.5]], method='linear')
array([ 4.7, 24.3])