Using numpy.interp I am able to compute the one-dimensional piecewise linear interpolant to a function with given values at discrete data-points.
Is it a similar function to return me the logarithmic interpolation?
解决方案
In the past, I've just wrapped the normal interpolation to do it in log-space, i.e.
def log_interp(zz, xx, yy):
logz = np.log10(zz)
logx = np.log10(xx)
logy = np.log10(yy)
return np.power(10.0, np.interp(logz, logx, logy))
Personally, I much prefer the scipy interpolation functions (as @mylesgallagher mentions), for example:
import scipy as sp
import scipy.interpolate
def log_interp1d(xx, yy, kind='linear'):
logx = np.log10(xx)
logy = np.log10(yy)
lin_interp = sp.interpolate.interp1d(logx, logy, kind=kind)
log_interp = lambda zz: np.power(10.0, lin_interp(np.log10(zz)))
return log_interp
Then you can just call this as a function on an arbitrary value.
博客围绕Python中对数处理展开,主要探讨对数插值问题。介绍了使用numpy.interp进行一维分段线性插值,还给出了对数插值的解决方案,包括自定义函数log_interp和使用scipy插值函数实现的log_interp1d。
1447

被折叠的 条评论
为什么被折叠?



