Python中的对数插值 [英] Logarithmic interpolation in python

查看:300
本文介绍了Python中的对数插值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用numpy.interp,我能够在离散数据点上为给定值的函数计算一维分段线性插值.

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))

我个人更喜欢 scipy内插函数(如@mylesgallagher所述),例如:

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中的对数插值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆