Search for a tool
Shannon Index

Tool to calculate the Shannon index. The Shannon index is a measure of entropy for characters strings (or any computer data)

Results

Shannon Index -

Tag(s) : Informatics, Cryptanalysis

Share dCode and more

dCode is free and its tools are a valuable help in games, maths, geocaching, puzzles and problems to solve every day!
A suggestion ? a feedback ? a bug ? an idea ? Write to dCode!

Please, check our dCode Discord community for help requests!
NB: for encrypted messages, test our automatic cipher identifier!

Thanks to your feedback and relevant comments, dCode has developed the best 'Shannon Index' tool, so feel free to write! Thank you!

# Shannon Index

## Shannon Index Calculator

### From a list of values

 These values are Number of occurences $n_i$ Frequencies $p_i$ A list of values

### What is Shannon's Entropy Index? (Definition)

Shannon's entropy index, as the name suggests, is a measure of the entropy that applies to any numerical data. It measures the frequencies of appearance of the items, and the more they are different, the more difficult it will be to predict the content (thus a greater uncertainty, and thus a greater entropy).

### How to calculate Shannon's Entropy? (Formula)

Entropy is calculated from a list of elements: in a text, the elements will be the characters and in an array of numeric values, the elements will be the numbers.

For a string of characters with $N$ items with $k$ distinct, each element $i$ having a number of occurence $n_i$ and a frequency of appearance $p_i ( = n_i/N )$. The entropy of Shannon $H$ is calculated according to the formula $$H = -\sum_{i=1}^k p_i \log_2 (p_i)$$

Example: DCODE has 5 characters (4 distinct), the letter D appears 2 times (frequency: 2/5), and the 3 letters C, O and E each appear 1 time (frequency: 1/5), the calculation is: $H = -\left( \frac{2}{5} \log_2(\frac{2}{5}) + 3 \times \frac{1}{5} \log_2(\frac{1}{5}) \right) \approx 1.921928$

The value is always positive, the logarithms of numbers less than 1 are always negative, their sum too, the sign - makes it possible to obtain a positive result.

### What is the Shannon index for?

From the Shannon index, the optimal encoding of a string can be deduced. If the Shannon index of a string is 3.5, then it will take 4 bits (rounded up) by characters to encode it optimally. The Shannon index can then be useful for evaluating a compression ratio, the higher the entropy, the better the compression.

## Source code

dCode retains ownership of the "Shannon Index" source code. Except explicit open source licence (indicated Creative Commons / free), the "Shannon Index" algorithm, the applet or snippet (converter, solver, encryption / decryption, encoding / decoding, ciphering / deciphering, translator), or the "Shannon Index" functions (calculate, convert, solve, decrypt / encrypt, decipher / cipher, decode / encode, translate) written in any informatic language (Python, Java, PHP, C#, Javascript, Matlab, etc.) and all data download, script, or API access for "Shannon Index" are not public, same for offline use on PC, mobile, tablet, iPhone or Android app!
Reminder : dCode is free to use.

## Cite dCode

The copy-paste of the page "Shannon Index" or any of its results, is allowed as long as you cite dCode!
Cite as source (bibliography):
Shannon Index on dCode.fr [online website], retrieved on 2022-08-08, https://www.dcode.fr/shannon-index

## Need Help ?

Please, check our dCode Discord community for help requests!
NB: for encrypted messages, test our automatic cipher identifier!