Issue
In jupyter notebook i tried to execute below code:
from math import log2
-((25/50)*log2(25/50))+((25/50)*log2(25/50))
output which am receiving is 0.0
it should be 1, what is the issue???
Solution
this is actually a math issue. not programming. the last thing must come in mind is that python is working wrong!
both sides of +
are equal and one of them has multiplied by -1. so it is like you are calculating this: -x+x
and it is equal to 0.
I guess you have this in mind: -((25/50) * log2(25/50) + (25/50) * log2(25/50))
. In this case, you will have an equation like:-(x+x)
. so you will get 1 for the answer.
>>> from math import log2
>>> -((25/50) * log2(25/50)) + ((25/50) * log2(25/50))
# 0.0
>>> -((25/50) * log2(25/50) + (25/50) * log2(25/50))
# 1.0
Answered By - FarZad
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.