Calculate logarithm in python

I am wondering why the result is log base 10 (1.5) in python = 0.405465108108 while the real answer = 0.176091259.

This is the code I wrote:

 import math print math.log(1.5) 

Does anyone know how to solve this problem.

+5
source share
4 answers

From the documentation :

With one argument, return the natural logarithm of x (to base e).

With two arguments, return the logarithm of x to the given base, calculated as log(x)/log(base) .

But log 10 is available as math.log10() , which does not resort to logarithmic division, if possible.

+15
source
 math.log10(1.5) 

Use the log10 function in the math module.

+6
source

The math.log function refers to the base e , that is, to the natural logarithm. If you want to use base 10, math.log10 .

+4
source

If you use a log without a base, it uses e .

From the comment

Returns the logarithm of x to the given base.
If the base is not specified, returns the natural logarithm (base e) x.

For this you need to use:

 import math print( math.log(1.5, 10)) 
+2
source

Source: https://habr.com/ru/post/1236134/


All Articles