cupyx.scipy.interpolate.interpn#
- cupyx.scipy.interpolate.interpn(points, values, xi, method='linear', bounds_error=True, fill_value=nan)[源代码][源代码]#
在规则或矩形网格上的多维插值。
严格来说,并非所有常规网格都受支持 - 此功能适用于 规则 网格,即具有均匀或不均匀间距的矩形网格。
- 参数:
points (tuple of cupy.ndarray of float, with shapes (m1, ), ..., (mn, )) – 定义 n 维规则网格的点。每个维度中的点(即 points 元组的每个元素)必须严格递增或递减。
values (cupy.ndarray of shape (m1, ..., mn, ...)) – n 维规则网格上的数据。复杂数据也是可以接受的。
xi (cupy.ndarray of shape (..., ndim)) – 采样网格数据的坐标
method (str, optional) – 要执行的插值方法。支持的方法有“linear”、“nearest”、“slinear”、“cubic”、“quintic”和“pchip”。
bounds_error (bool, optional) – 如果为 True,当请求的插值值超出输入数据的范围时,会引发 ValueError。如果为 False,则使用 fill_value。
fill_value (number, optional) – 如果提供,则使用此值作为插值域之外的点的值。如果为 None,则域外的值将被外推。
- 返回:
values_x – 在 xi 处的插值值。当
xi.ndim == 1时的行为请参见注释。- 返回类型:
ndarray, shape xi.shape[:-1] + values.shape[ndim:]
备注
在
xi.ndim == 1的情况下,一个新的轴被插入到返回数组 values_x 的第 0 位置,因此其形状变为(1,) + values.shape[ndim:]。如果输入数据使得输入维度的单位不一致且相差多个数量级,插值函数可能会出现数值伪影。建议在插值前重新调整数据。
示例
在规则的3-D网格点上评估一个简单的示例函数:
>>> import cupy as cp >>> from cupyx.scipy.interpolate import interpn >>> def value_func_3d(x, y, z): ... return 2 * x + 3 * y - z >>> x = cp.linspace(0, 4, 5) >>> y = cp.linspace(0, 5, 6) >>> z = cp.linspace(0, 6, 7) >>> points = (x, y, z) >>> values = value_func_3d(*cp.meshgrid(*points, indexing='ij'))
在一点处评估插值函数
>>> point = cp.array([2.21, 3.12, 1.15]) >>> print(interpn(points, values, point)) [12.63]
参见
RegularGridInterpolator在任意维度的规则或矩形网格上的插值(interpn 封装了这个类)。
cupyx.scipy.ndimage.map_coordinates在等间距网格上的插值(适用于例如 N-D 图像重采样)