Skip to content

Commit 64bb08d

Browse files
committed
add readme with example
1 parent caf365f commit 64bb08d

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

README.md

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
Installation
2+
============
3+
4+
pip install range-coder
5+
6+
7+
Example
8+
=======
9+
10+
```python
11+
from range_coder import RangeEncoder, RangeDecoder, prob_to_cum_freq
12+
13+
data = [2, 0, 1, 0, 0, 0, 1, 2, 2]
14+
prob = [0.5, 0.2, 0.3]
15+
16+
# convert probabilities to cumulative integer frequency table
17+
cumFreq = prob_to_cum_freq(prob, resolution=128)
18+
19+
# encode data
20+
encoder = RangeEncoder(filepath)
21+
encoder.encode(data, cumFreq)
22+
encoder.close()
23+
24+
# decode data
25+
decoder = RangeDecoder(filepath)
26+
dataRec = decoder.decode(len(data), cumFreq)
27+
decoder.close()
28+
```

0 commit comments

Comments
 (0)