Previous topic

mipylib.numeric.interpolate

Next topic

RectBivariateSpline

This Page

interp1d

class numeric.interpolate.interp1d(object)

Interpolate a 1-D function.

Parameters:
  • x – (array_like) A 1-D array of real values.
  • y – (array_like) A 1-D array of real values. The length of y must be equal to the length of x.
  • kind – (boolean) Specifies the kind of interpolation as a string (‘linear’, ‘cubic’,‘akima’,‘divided’,‘loess’,‘neville’). Default is ‘linear’.

Examples:

from mipylib.numeric import interpolate

x = linspace(0, 10, num=11, endpoint=True)
y = cos(-x**2/9.0)
f = interpolate.interp1d(x, y)
f2 = interpolate.interp1d(x, y, kind='cubic')

xnew = linspace(0, 10, num=100, endpoint=True)
plot(x, y, 'bo', xnew, f(xnew), 'g-', xnew, f2(xnew), 'r--')
ylim(-1.5, 1.2)
legend(['data','linear','cubic'], loc='lower left')
title('Interpolation example')
../../../../_images/interp1d.png