Log to the base 2 in python

前端 未结 11 1168
刺人心
刺人心 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条回答
  •  Happy的楠姐
    2020-12-07 15:45

    >>> def log2( x ):
    ...     return math.log( x ) / math.log( 2 )
    ... 
    >>> log2( 2 )
    1.0
    >>> log2( 4 )
    2.0
    >>> log2( 8 )
    3.0
    >>> log2( 2.4 )
    1.2630344058337937
    >>> 
    

提交回复
热议问题