mindspore.numpy.interp

mindspore.numpy.interp(x, xp, fp, left=None, right=None)[source]

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.

Note

Numpy argument period is not supported. Complex values are not supported.

Parameters
  • 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 is fp[0].

  • right (float, optional) – Value to return for x > xp[-1], default is fp[-1].

Returns

Tensor, the interpolated values, same shape as x.

Raises

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

Examples

>>> 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