Skip to content
DeepForgeby svx
All problems
EasyInformation Theoryinfo-005

Joint Entropy of a Distribution

Problem

Compute the joint entropy in bits of a 2D joint distribution joint[x][y]:

H(X, Y) = -sum(p * log2(p))

Skip zero entries.

Hint

Flatten the table conceptually and treat every cell as one outcome.

Test cases

case 1
in: [[[0.25,0.25],[0.25,0.25]]]
expected: 2
case 2
in: [[[0.5,0],[0,0.5]]]
expected: 1
case 3
in: [[[1]]]
expected: 0
case 4
in: [[[0.1,0.2],[0.3,0.4]]]
expected: 1.8464393446710154
Starter codePython
import math
def joint_entropy(joint):
    # Your code here
    pass

4 test cases · run your code against them in the editor