Log to the base 2 in python

前端 未结 11 1180
刺人心
刺人心 2020-12-07 15:22

How should I compute log to the base two in python. Eg. I have this equation where I am using log base 2

import math
e = -(t/T)* math.log((t/T)[, 2])
         


        
11条回答
  •  鱼传尺愫
    2020-12-07 15:53

    It's good to know that

    alt text

    but also know that math.log takes an optional second argument which allows you to specify the base:

    In [22]: import math
    
    In [23]: math.log?
    Type:       builtin_function_or_method
    Base Class: 
    String Form:    
    Namespace:  Interactive
    Docstring:
        log(x[, base]) -> the logarithm of x to the given base.
        If the base not specified, returns the natural logarithm (base e) of x.
    
    
    In [25]: math.log(8,2)
    Out[25]: 3.0
    

提交回复
热议问题