[SciPy-User] Logarithmic interpolation
Thomas Robitaille
thomas.robitaille@gmail....
Thu Jul 29 10:10:14 CDT 2010
Hello,
For a problem I am trying to solve, I need to perform interpolation, but in log-log space, or linear-log space. The obvious way to do this is to do something like
f = interp1d(np.log10(x), np.log10(y))
ynew = 10.**f(np.log10(xnew))
but this can actually be pretty inefficient, because the log of all the values in x and y has to be computed. So for arrays of size e.g. 100, the above requires 201 calls to the log function. A more efficient way for interpolation of a single value would be to basically search where xnew falls in x, say between x[i] and x[i+1], and then do the log interpolation using only 4 calls to log10:
ynew = 10.**(np.log10(y[i+1]/y[i]) / np.log10(x[i+1]/x[i]) * np.log10(xnew/x[i]) + np.log10(y[i]))
Is there a way to already do this more easily somewhere in scipy.interpolate?
Thanks,
Thomas
More information about the SciPy-User
mailing list