Search notes:

Python library math - logarithmic functions

import math

#
#  log(x) - natural logarithm of x
#
print(math.log(math.e))  # --> 1

#
#  log(x, b) - logarithm of x to the given base
#
print(math.log(256, 4)) # --> 4.0

#
#  log10(x) - base 10 logarithm of x ( usually more accurate than log(x, 10) )
#
print(math.log10(1000)) # --> 3.0

#
#  log2(x) - base 2 logarithm of x   ( usually more accurate than log(x, 2) )
#
print(math.log2(256))       # --> 8.0

#
#  log1p(x) == log(x+1)  (calculated in a way which is accurate for x near zero)
#
print(math.log1p(math.e-1)) # --> 1.0


Index