Log to the base 2 in python

前端 未结 11 1169
刺人心
刺人心 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 16:07

    If you are on python 3.3 or above then it already has a built-in function for computing log2(x)

    import math
    'finds log base2 of x'
    answer = math.log2(x)
    

    If you are on older version of python then you can do like this

    import math
    'finds log base2 of x'
    answer = math.log(x)/math.log(2)
    

提交回复
热议问题