mindspore.numpy.interp
- mindspore.numpy.interp(x, xp, fp, left=None, right=None)[源代码]
One-dimensional linear interpolation for monotonically increasing sample points. Returns the one-dimensional piecewise linear interpolant to a function with given discrete data points (xp, fp), evaluated at x.
说明
Numpy argument period is not supported. Complex values are not supported.
- 参数
x (Union[int, float, bool, list, tuple, Tensor]) – The x-coordinates at which to evaluate the interpolated values.
xp (Union[int, float, bool, list, tuple, Tensor]) – 1-D sequence of floats, the x-coordinates of the data points, must be increasing.
fp (Union[int, float, bool, list, tuple, Tensor]) – 1-D sequence of floats, the y-coordinates of the data points, same length as xp.
left (float, optional) – Value to return for
x < xp[0]
, default isfp[0]
once obtained.right (float, optional) – Value to return for
x > xp[-1]
, default isfp[-1]
once obtained.
- 返回
Tensor, the interpolated values, same shape as x.
- 异常
ValueError – If xp or fp is not one-dimensional, or if xp and fp do not have the same length.
- Supported Platforms:
Ascend
GPU
CPU
样例
>>> import mindspore.numpy as np >>> xp = [1, 2, 3] >>> fp = [3, 2, 0] >>> print(np.interp([0, 1, 1.5, 2.72, 3.14], xp, fp)) [3. 3. 2.5 0.55999994 0. ] >>> UNDEF = -99.0 >>> print(np.interp(3.14, xp, fp, right=UNDEF)) -99.0