python math模块中的log2 [英] log2 in python math module
问题描述
为什么不存在?
import math
[x for x in dir(math) if 'log' in x]
>>> ['log', 'log10', 'log1p']
我知道我可以做log(x,2),但是log2确实很常见,所以我有点困惑.
I know I can do log(x,2), but log2 is really common, so I'm kind of baffled.
哦,看来它仅在C99中定义,而不是在C90中定义,我想这回答了我的问题.还是有点傻.
Oh, it looks like it's only defined in C99, not C90, I guess that answers my question. Still seems kind of silly.
推荐答案
我认为您已经回答了自己的问题. :-)没有log2(x)
,因为您可以执行log(x, 2)
.正如Python的禅宗( PEP 20 )所说,应该有一个-而且最好只有一种-很明显的方式."
I think you've answered your own question. :-) There's no log2(x)
because you can do log(x, 2)
. As The Zen of Python (PEP 20) says, "There should be one-- and preferably only one --obvious way to do it."
也就是说,在问题3366 (向下滚动到最后3条消息)中考虑了log2
在math
模块中为Python 2.7和3.2添加了其他C99数学函数.
That said, log2
was considered in Issue3366 (scroll down to the last 3 messages) which added several other C99 math functions to the math
module for Python 2.7 and 3.2.
编辑:在 Issue11888 中重新考虑了log2,并在Python 3.3中进行了添加.
Edit: log2 was reconsidered in Issue11888 and added in Python 3.3.
这篇关于python math模块中的log2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!