Resampling sampled data
Estimate values between measured samples on a one-dimensional coordinate grid.
SciPy · Class
Creates a callable interpolator for one-dimensional sampled data. It supports linear, nearest-neighbor, spline-based, and directional interpolation with configurable axis and out-of-range behavior.
Create an interpolator from one-dimensional coordinates and corresponding values, then call the returned object with new coordinates. The selected kind controls how values between samples are estimated, while axis selects the dimension of multidimensional y that corresponds to x.
scipy.interpolate.interp1d(x, y, kind='linear', axis=-1, copy=True, bounds_error=None, fill_value=nan, assume_sorted=False)| Name | Type | Description |
|---|---|---|
x | array_like | One-dimensional array of real sample coordinates. |
y | array_like | N-dimensional real values; its length along the interpolation axis must match x. |
kind | str or int, optional | Interpolation method name or spline order; default is linear. |
axis | int, optional | Axis of y corresponding to x; default is -1. |
copy | bool, optional | Whether to copy input arrays; default is True. |
bounds_error | bool, optional | Controls whether out-of-range evaluation raises ValueError. |
fill_value | array-like or two-element tuple, optional | Value assigned outside the x range when bounds_error is False; default is nan. |
assume_sorted | bool, optional | If True, x is assumed sorted and is not sorted internally; default is False. |
A callable interpolator that evaluates estimated values at new points.
import numpy as np
from scipy.interpolate import interp1d
x = np.array([0.0, 1.0, 2.0])
y = np.array([0.0, 1.0, 4.0])
f = interp1d(x, y, kind="linear")
print(f([0.5, 1.5])) # [0.5 2.5]Creates a linear interpolator from known points and evaluates it at two intermediate coordinates.
Estimate values between measured samples on a one-dimensional coordinate grid.
Evaluate vector- or tensor-valued samples along one selected dimension.
Choose nearest, spline, previous, or next behavior for application-specific lookup rules.
interp1d builds a callable interpolator from x and y samples. Calling that object estimates values at new x coordinates using the requested interpolation kind.
Follow-up: How would you handle multidimensional y? Set axis to the dimension containing the sample sequence, whose length must equal x.
The default kind is linear. Other choices include nearest, zero, slinear, quadratic, cubic, previous, and next; an integer can specify spline order.
Follow-up: Which parameter controls the sampled dimension? axis does, and its default is the last axis of y.
bounds_error determines behavior outside the x range: True raises ValueError, while False assigns fill_value. The default bounds_error=None is resolved together with fill_value according to the documented boundary behavior.
Follow-up: How can endpoint values be used for out-of-range inputs? Supply a two-element fill_value for below- and above-range values.
scipy.interpolate.CubicSplinescipy.interpolate.PchipInterpolatorscipy.interpolate.Akima1DInterpolator