I often need to make a linear interpolation for a single scalar value but this is not very simple with numpy.interp :
import numpy as n n.__version__
xp = n.arange(10) yp = 2.5 + xp**2 -x x = 3.2 n.interp(x, xp, yp)
Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: object of too small depth for desired array
So I use the following trick (which is really ugly) :
n.interp([x], xp, yp)
Did I miss an obvious way to do it ?
If not, I'd be tempted to patch interp to let it accept scalar values as first argument as follow :
def interp(x, *args, **kwds):
... if type(x) in (float, int): ... return n.interp([x], *args, **kwds).item() ... else : ... return n.interp(x, *args, **kwds) ...
interp(x, xp, yp)
interp([x,2*x], xp, yp)
array([ 7.7, 38.5])