[SciPy-user] Arrayfns in numpy?

Stephen Kelly steveire@gmail....
Mon Mar 26 11:59:16 CDT 2007

Here is the function I'm using after the advice of Alok Singhal above.
Just thought I'd post it in case someone else is looking for similar.

def interp(y_values, x_values, new_x_values):
  """ Perform interpolation similar to deprecated arrayfns.interp in Numeric.

  interp(y, x, z) = y(z) interpolated by treating y(x) as piecewise fcn.
  x = array(x_values, dtype='float')
  y = array(y_values, dtype='float')

  xx = array(new_x_values, dtype='float')
  # High indices
  hi = searchsorted(x, xx)

  # Low indices
  lo = hi - 1

  slopes = (y[hi] - y[lo])/(x[hi] - x[lo])

  # Interpolated data
  yy = y[lo] + slopes*(xx - x[lo])
  return yy

It gives almost identical results for my data, except for points out
of range for which it creates zeros unlike arrayfns.

Thanks again for the help.


More information about the SciPy-user mailing list