Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

calculate entropy

import numpy as np

# 3 decimal points
round = 3

# entropy(q) = -( q * log2(q) + (1-q) * log2(1-q) )
def entropy(q):
    entropy = -(q * np.log2(q) + (1-q) * np.log2(1-q))
    entropy = np.round(entropy, round)
    return entropy
  
# print(entropy(0.3)) = 0.881
Comment

PREVIOUS NEXT
Code Example
Python :: python expression factorisation 
Python :: How to convert a string to a dataframe in Python 
Python :: valid parentheses with python 
Python :: how to convert a list into string with  
Python :: get home directory in windows python os 
Python :: python number of elements in multidimensional array 
Python :: plt ax title 
Python :: Access the Response Methods and Attributes in python Show Status Code 
Python :: print without changing line python 
Python :: new working version of linkchecker 
Python :: pandas diff between dates 
Python :: create additional rows for missing dates pandas 
Python :: plotly not showing in colab 
Python :: askopenfilename 
Python :: django login redirect 
Python :: how to manke a query in google api freebusy python 
Python :: exact distance math 
Python :: add empty column to dataframe pandas 
Python :: requests get cookies from response 
Python :: how to add scrollbar to listbox in tkinter 
Python :: django message framework 
Python :: how to convert list into string in python 
Python :: np zeros in more dimensions 
Python :: python class get attribute by name 
Python :: python turn 0 into 1 and vice versa 
Python :: plt axis tick color 
Python :: time date in pandas to csv file 
Python :: rerun file after change python 
Python :: count number of words in a string python 
Python :: drop second column pandas 
ADD CONTENT
Topic
Content
Source link
Name
8+8 =