[SciPy-User] interp1d and out of bounds values

Thomas Robitaille thomas.robitaille@gmail....
Fri Jan 22 11:17:20 CST 2010


Hello,

I've been using scipy.interpolate.interp1d to interpolate values in a number of different projects. However, something I often need is the following: if the interpolating function is defined as f(x) from xmin to xmax, if I specify an x value smaller than xmin, I would like the value set to f(xmin), and if the value is above xmax, I would like the value set to xmax. While this is strictly extrapolation, I'm wondering if there is a way that fill_value could be set to a certain string value, for example 'nearest', to indicate that this is the desired behavior? I could see this being commonly used. If it is not possible to modify scipy directly, what would be the best way to wrap interp1d to allow this? Since interp1d(x,y) takes y as an n-dimensional array, I'm not sure how I could code this up.

Thanks in advance for any advice,

Thomas


More information about the SciPy-User mailing list