Skip to content
DeepForgeby svx
All problems
EasyInformation Theoryinfo-068

Arithmetic Coding CDF

Problem

Return the cumulative distribution boundaries used by an arithmetic coder: a list starting with 0.0 followed by the running cumulative sums of probs, so the result has len(probs) + 1 entries.

Hint

Symbol i occupies the interval [cdf[i], cdf[i + 1]).

Test cases

case 1
in: [[0.5,0.5]]
expected: [0,0.5,1]
case 2
in: [[0.25,0.25,0.25,0.25]]
expected: [0,0.25,0.5,0.75,1]
case 3
in: [[0.1,0.2,0.7]]
expected: [0,0.1,0.30000000000000004,1]
case 4
in: [[1]]
expected: [0,1]
Starter codePython
def arithmetic_cdf(probs):
    # Your code here
    pass

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