0

Want to do calculation using the numbers in 2D array

import math 
result = 0
data = [[0],[1],[1],[1],[0],[1],[1],[1]]
for i in data:
    result += (math.log(i[0], 2))

The reported error is ValueError: math domain error

Could someone show me what's wrong with this code?

Francesco
  • 4,052
  • 2
  • 21
  • 29
Echo0831
  • 307
  • 2
  • 5
  • 14

1 Answers1

1

log 0 is undefined. It's not a real number, because you can never get zero by raising anything to the power of anything else. You can never reach zero, you can only approach it using an infinitely large and negative power. 3.

>>> math.log(0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: math domain error
Hackaholic
  • 19,069
  • 5
  • 54
  • 72