-
Notifications
You must be signed in to change notification settings - Fork 93
/
Compress data in a array.py
80 lines (74 loc) · 5.14 KB
/
Compress data in a array.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
from sys import getsizeof
import lzhw
sample_data = [46, 90, 43, 36, 57, 40, 1, 73, 47, 52, 70, 93, 53, 100,
49, 75, 72, 30, 63, 70, 44, 73, 67, 19, 41, 83, 46, 5, 81, 97, 85, 10,
32, 92, 97, 41, 2, 32, 98, 10, 39, 90, 43, 16, 45, 46, 46, 46, 59, 28,
23, 23, 56, 63, 62, 1, 37, 90, 0, 34, 89, 23, 61, 97, 11, 27, 31, 10,
3, 89, 15, 33, 75, 46, 17, 66, 86, 93, 91, 82, 39, 64, 16, 68, 87, 0,
66, 51, 73, 51, 15, 99, 36, 83, 53, 62, 46, 3, 35, 77, 88, 8, 45, 73,
27, 37, 75, 9, 99, 30, 18, 81, 94, 37, 60, 30, 31, 63, 20, 49, 39, 19,
42, 45, 12, 82, 91, 40, 43, 3, 23, 66, 76, 97, 94, 5, 50, 27, 34, 12, 37,
2, 3, 49, 35, 93, 52, 24, 40, 4, 53, 29, 31, 45, 87, 86, 48, 1, 14, 68,
92, 28, 16, 4, 94, 10, 47, 5, 98, 100, 45, 23, 84, 15, 41, 68, 9, 79, 41,
34, 84, 10, 18, 71, 44, 36, 3, 57, 4, 45, 43, 2, 44, 0, 36, 74, 76, 50,
95, 15, 31, 28, 39, 44, 98, 99, 59, 15, 51, 85, 58, 72, 67, 73, 20, 15,
15, 81, 68, 80, 70, 68, 42, 70, 19, 10, 64, 81, 89, 32, 71, 54, 47, 25,
7, 62, 87, 91, 57, 30, 86, 34, 34, 70, 28, 47, 38, 84, 68, 20, 68, 10,
67, 19, 28, 96, 32, 84, 49, 51, 15, 24, 31, 33, 42, 6, 51, 32, 16, 41,
52, 88, 27, 42, 96, 94, 47, 17, 49, 100, 51, 93, 33, 67, 62, 67, 77,
72, 0, 54, 3, 38, 15, 96, 46, 44, 88, 22, 28, 52, 8, 78, 16, 76, 34,
63, 5, 80, 23, 47, 2, 80, 23, 10, 4, 83, 33, 4, 48, 69, 11, 91, 94,
35, 65, 69, 47, 75, 59, 86, 65, 36, 96, 37, 73, 55, 69, 84, 78, 58,
16, 57, 71, 28, 22, 56, 0, 12, 61, 85, 70, 54, 36, 54, 16, 35, 42,
27, 33, 12, 67, 74, 28, 69, 71, 99, 56, 20, 21, 10, 51, 95, 20, 10,
86, 7, 69, 90, 89, 29, 16, 35, 12, 83, 40, 71, 40, 70, 91, 3, 22, 13,
28, 29, 92, 90, 48, 0, 83, 15, 85, 51, 51, 12, 21, 57, 86, 97, 87, 5,
9, 82, 56, 92, 19, 78, 31, 10, 68, 34, 96, 62, 33, 48, 93, 26, 98, 75,
3, 5, 4, 29, 79, 9, 52, 23, 99, 3, 84, 28, 77, 85, 46, 59, 73, 92, 93,
10, 45, 61, 29, 14, 8, 1, 86, 10, 46, 16, 91, 84, 86, 4, 80, 51, 58,
28, 80, 8, 96, 71, 100, 26, 48, 27, 41, 51, 4, 19, 22, 8, 30, 2, 55,
64, 78, 43, 75, 43, 82, 43, 86, 31, 100, 18, 4, 34, 25, 43, 92, 30,
43, 92, 32, 35, 3, 49, 65, 15, 58, 95, 43, 58, 67, 74, 43, 27, 55,
55, 77, 93, 38, 77, 40, 92, 68, 18, 75, 22, 36, 65, 40, 19, 19, 18,
19, 21, 70, 12, 49, 59, 31, 29, 75, 47, 11, 71, 92, 36, 28, 64, 66,
36, 95, 93, 77, 28, 30, 13, 3, 29, 8, 40, 9, 51, 19, 28, 31, 8, 69,
10, 93, 4, 81, 56, 76, 55, 42, 10, 77, 2, 53, 7, 47, 88, 30, 0, 64,
13, 37, 47, 56, 95, 27, 18, 31, 23, 26, 92, 100, 22, 100, 31, 34,
84, 19, 69, 85, 93, 73, 9, 57, 22, 53, 28, 16, 48, 10, 12, 77, 95,
11, 20, 20, 34, 86, 41, 43, 34, 2, 73, 63, 35, 52, 85, 45, 53, 69,
16, 32, 63, 80, 12, 60, 45, 66, 99, 54, 55, 18, 48, 88, 16, 73, 62,
54, 48, 100, 43, 19, 89, 97, 92, 86, 16, 96, 26, 41, 50, 68, 3, 22,
33, 88, 16, 81, 26, 46, 35, 90, 43, 39, 100, 22, 44, 69, 97, 22, 94,
49, 44, 79, 60, 0, 95, 25, 51, 52, 41, 13, 47, 79, 22, 42, 40, 93,
24, 42, 16, 91, 14, 67, 86, 58, 20, 45, 72, 70, 5, 71, 26, 30, 75,
58, 70, 70, 38, 83, 36, 62, 88, 23, 6, 93, 9, 97, 35, 20, 67, 60,
69, 11, 53, 96, 33, 49, 93, 31, 90, 76, 77, 22, 42, 48, 31, 13,
85, 35, 68, 93, 12, 27, 89, 77, 98, 6, 11, 17, 5, 15, 20, 5, 63,
18, 29, 96, 97, 31, 32, 79, 6, 38, 30, 72, 22, 80, 36, 39, 3, 49, 83,
41, 0, 14, 42, 4, 39, 30, 39, 25, 17, 24, 84, 8, 55, 99, 32, 36, 61,
56, 64, 97, 18, 27, 72, 86, 80, 73, 48, 21, 80, 45, 32, 8, 14, 50, 89,
66, 23, 39, 57, 1, 58, 87, 64, 75, 54, 6, 100, 10, 57, 22, 51, 43, 78,
78, 18, 47, 26, 2, 96, 25, 32, 59, 38, 87, 5, 54, 53, 57, 40, 36, 30, 60,
38, 55, 75, 91, 24, 14, 91, 38, 78, 81, 58, 96, 47, 46, 88, 24, 2, 60, 94,
12, 55, 65, 60, 50, 42, 45, 19, 39, 25, 33, 98, 41, 74, 2, 33, 34, 41, 28,
49, 79, 96, 79, 78, 9, 2, 93, 76, 1, 43, 10, 95, 86, 29, 69, 34, 7, 95, 24,
5, 92, 97, 88, 96, 56, 93, 51, 96, 84, 72, 60, 66, 42, 97, 99, 50, 51, 92,
94, 9, 91, 77, 73, 97, 14, 5, 43, 76, 55, 33, 97, 99, 34, 25, 3, 25, 47, 32,
60, 84, 13, 63, 15, 86, 19, 81, 90, 78, 32, 42, 72, 84, 27, 95, 73, 94, 65,
96, 60, 8, 1, 60, 19, 2, 81, 25, 41, 70, 33, 79, 65, 3, 88, 78, 55, 53, 51, 11]
compressed = lzhw.LZHW(sample_data)
# let's see how the compressed object looks like:
print(compressed.compressed)
# (524288, 524288, 81592676324)
# its size
print(compressed.size())
# 72
# size of original
print(getsizeof(sample_data))
# 216
print(compressed.space_saving())
# space saving from original to compressed is 67%
# Let's decompress and check whether there is any information loss
decomp = compressed.decompress()
print(all(decomp == sample_data))
# True