Skip to main content
 首页 » 编程设计

python之math.log(x) 在 Python 中返回意外结果

2025年05月04日12youxin

我正在尝试使用 Python 进行一些基本的 dB 计算。如果我使用 Excel 或科学计算器:

20*log(0.1) = -20 

在 Python 中:

20*log(0.1) = -46.0517018599 

为了进一步简化,Excel 和 Scientific calc:

log(0.1) = -1 

python :

log(0.1) = -2.30258509299 

我用

开始我的脚本
import math 
 
log = math.log 

谁能解释这是为什么以及我该如何解决?

请您参考如下方法:

math.log 实际上是 ln(基数为 e)。要获得预期结果,请使用 math.log(0.1, 10) 或 math.log10(0.1)。