Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

SciPy · Function

interpolate.griddata

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.

How it works

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.

Syntax

scipy.interpolate.griddata(points, values, xi, method='linear', fill_value=nan, rescale=False)

Parameters

NameTypeDescription
points2-D ndarray of floats or tuple of 1-D ndarraysCoordinates of the data points: an array with shape (n, D), or a length-D tuple of arrays with shape (n,).
valuesndarray of float or complexData values associated with the input points; shape (n,).
xi2-D ndarray of floats or tuple of ndarraysLocations where values should be interpolated: an array with shape (m, D), or a tuple of broadcastable coordinate arrays.
method{'linear', 'nearest', 'cubic'}, optionalInterpolation rule: 'linear', 'nearest', or 'cubic'.
fill_valuefloat, optionalValue assigned outside the convex hull when applicable; default is NaN.
rescalebool, optionalWhether to rescale coordinates to the unit cube before interpolation.

Returns

ndarray of interpolated values

Key points

  • griddata is a convenience function for interpolating data whose sample points are not arranged on a regular grid.
  • Input coordinates can be represented as an n-by-D array or as D coordinate arrays.
  • Query locations support row-wise coordinates or broadcastable coordinate arrays.
  • Linear interpolation works simplex by simplex after tessellating the input points.
  • Nearest interpolation chooses the sample value associated with the closest data point.
  • In one dimension, cubic interpolation uses a cubic spline.
  • rescale transforms coordinate dimensions to a unit-cube scale before interpolation.

Common mistakes

  • Use rescale when coordinate dimensions have substantially different numerical scales.

Example: Linear interpolation on unstructured points

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.

When to use it

Scattered-data interpolation

Estimate values at locations between scattered measurements.

Generate a regularized field

Evaluate irregular samples on a mesh or coordinate grid.

Scale disparate coordinates

Combine features measured in units with very different scales.

Interview questions

QWhat inputs does griddata require?

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.

QHow do the interpolation methods differ?

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.

QWhat does griddata return?

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.

  • NearestNDInterpolator
  • LinearNDInterpolator
  • CloughTocher2DInterpolator
  • interp1d

Source: scipy.interpolate.griddata. Checked 2026-10-15.