ndarray_linear_interpolation#
- regridding.ndarray_linear_interpolation(a, indices, axis=None, axis_indices=None)[source]#
Interpolate a
numpy.ndarrayonto a new grid.Similar to
scipy.ndimage.map_coordinates(), but allows for interpolation along only some of the axes ofa.- Parameters:
a (ndarray) – The input array to be interpolated. Should have at least as many axes as
len(indices)indices (tuple[ndarray, ...]) – The new indices where
awill be evaluated. The number of indices,len(indices)should be equal to the number of interpolation axes,len(axis)axis (None | int | tuple[int, ...]) – The axes of
ato interpolate. IfNone, interpolate over all the axes ofa.axis_indices (None | int | tuple[int, ...]) – The axes of
indicesthat are complementary to the axes inaxis. IfNone, all axes of indices are complementary to the axes inaxis.
- Return type:
The interpolated array
Examples
import numpy as np import matplotlib.pyplot as plt import regridding x = np.arange(5) y = np.arange(6)
Interpolate a 1D array
a = x * x x_new = np.linspace(0, x.size - 1, num=20) a_new = regridding.ndarray_linear_interpolation(a, indices=(x_new, )) plt.figure(figsize=(6, 3)); plt.scatter(x, a, s=100, label="original", zorder=1); plt.scatter(x_new, a_new, label="interpolated", zorder=0); plt.legend();