numpy.interp

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

One-dimensional linear interpolation.

Returns the one-dimensional piecewise linear interpolant to a function with given values at discrete data-points.

Parameters :

x : array_like

The x-coordinates of the interpolated values.

xp : 1-D sequence of floats

The x-coordinates of the data points, must be increasing.

fp : 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], defaults is fp[-1].

Returns :

y : {float, ndarray}

The interpolated values, same shape as x.

Raises :

ValueError :

If xp and fp have different length

Notes

Does not check that the x-coordinate sequence xp is increasing. If xp is not increasing, the results are nonsense. A simple check for increasingness is:

np.all(np.diff(xp) > 0)

Examples

Previous topic

numpy.real_if_close

Next topic

Matrix library (numpy.matlib)

This Page