Doubt in entropy function

why np.log2 in entropy code

Hey sweta,
According to the formula -sigma(pi*log(pi)) We need to take log values for calculating entropy. Explanation is given in the video about this formula, in code we are just implementing this formula in python.

Thanks :slight_smile:

hiii
why log2 is used ,why 2 as the base?

Hi,
the significance of 2 here is nothing much,
You can take other base as well.
logab = logcb / logca

Hence, if you use other base, such as e and 10, you can always convert to another base using a scalar multiplication according to the above formula
But generally in computer we work with bases 2, unless specified explicitly, because information in the smallest unit bits can be divided in 2 parts only.

I hope this clears your doubts

1 Like

Yes doubt is cleared .Thank you Sir!

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.