Scattered-data interpolation
Estimate values at locations between scattered measurements.
SciPy · Function
Interpolates unstructured data in multiple dimensions at specified query points. Choose linear, nearest, or cubic interpolation and optionally rescale coordinates or provide an exterior fill value.
Pass coordinate/value pairs and query coordinates to construct interpolated values. The selected method determines the interpolation rule, while fill_value handles points outside the input domain and rescale can normalize differently scaled coordinates.
scipy.interpolate.griddata(points, values, xi, method='linear', fill_value=nan, rescale=False)| Name | Type | Description |
|---|---|---|
points | 2-D ndarray of floats or tuple of 1-D ndarrays | Coordinates of the data points: an array with shape (n, D), or a length-D tuple of arrays with shape (n,). |
values | ndarray of float or complex | Data values associated with the input points; shape (n,). |
xi | 2-D ndarray of floats or tuple of ndarrays | Locations where values should be interpolated: an array with shape (m, D), or a tuple of broadcastable coordinate arrays. |
method | {'linear', 'nearest', 'cubic'}, optional | Interpolation rule: 'linear', 'nearest', or 'cubic'. |
fill_value | float, optional | Value assigned outside the convex hull when applicable; default is NaN. |
rescale | bool, optional | Whether to rescale coordinates to the unit cube before interpolation. |
ndarray of interpolated values
import numpy as np
from scipy.interpolate import griddata
points = np.array([[0, 0], [1, 0], [0, 1], [1, 1]])
values = np.array([0.0, 1.0, 1.0, 2.0])
query = np.array([[0.5, 0.5], [2.0, 2.0]])
result = griddata(points, values, query, method="linear", fill_value=-1.0)
print(result) # [ 1. -1.]Interpolates values at two query points; the exterior point receives the chosen fill value.
Estimate values at locations between scattered measurements.
Evaluate irregular samples on a mesh or coordinate grid.
Combine features measured in units with very different scales.
It accepts point coordinates, their values, and query coordinates. points and xi may be arrays of coordinate rows or tuples of coordinate arrays.
Follow-up: How can query coordinates be supplied in grid form? Provide a tuple of broadcastable coordinate arrays.
The default is linear interpolation. Nearest selects the value at the closest input point, while linear tessellates the points into simplices and interpolates within them.
Follow-up: What happens to a linear query outside the input domain? It receives fill_value, whose default is NaN.
The returned object is an ndarray of interpolated values. Its shape follows the query representation: row queries produce one value per row, while broadcastable coordinate arrays produce the broadcast shape.
Follow-up: Which method supports a two-dimensional piecewise cubic surface? The cubic method does, using a continuously differentiable approximately curvature-minimizing surface.
NearestNDInterpolatorLinearNDInterpolatorCloughTocher2DInterpolatorinterp1d