Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calculate logarithm in python

Tags:

python

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

This is the code that I wrote:

import math print math.log(1.5) 

Can someone tell how to solve this issue?

like image 290
Nasser Avatar asked Nov 17 '15 10:11

Nasser


People also ask

How do you log data in Python?

1. log(a,(Base)) : This function is used to compute the natural logarithm (Base e) of a. If 2 arguments are passed, it computes the logarithm of the desired base of argument a, numerically value of log(a)/log(Base). Syntax : math.

How do you do log 2 in Python?

Python log2(x) is a built-in function used to get the logarithm of any given number with base 2. The log2(x) function is under the math library, so we need to import the math library to use the log2() function.

What is the math log function in Python?

The log() function in Python calculates the logarithm of a number to the base or calculates the natural logarithm of a number if the base is not specified by the user. The following illustration shows the mathematical representation of the log() function. The math module is required in order to use this function.


1 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 the log10 is made available as math.log10(), which does not resort to log division if possible.

like image 134
Ignacio Vazquez-Abrams Avatar answered Oct 15 '22 17:10

Ignacio Vazquez-Abrams