Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python logarithm

Tags:

python

i want to find out a log10 of an integer in python and i get an error like math domain error

my code is this w=math.log10(q*q1)/math.log10(2)

where q1,q2 are integers

yeah q1 is 0 sometimes

like image 404
Hick Avatar asked Nov 30 '22 20:11

Hick


2 Answers

You can only compute the logarithm of a positive number. Trying to compute the logarithm for a negative number or zero will result in a "math domain error" in Python.

By the way: it looks like you're actually trying to compute a logarithm base 2. You can do this with math.log:

w=math.log(q*q1, 2)

The second, optional, parameter is the base. It defaults to e (ie: natural log).

like image 64
Laurence Gonsalves Avatar answered Dec 06 '22 10:12

Laurence Gonsalves


Is q or q1 equal to zero or one of them negative?

like image 37
Mitch Wheat Avatar answered Dec 06 '22 09:12

Mitch Wheat