Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import struct
- def compress(file):
- print(file)
- size = len(file)
- dict = {}
- dict_int = {}
- list = sorted(file)
- for num in list:
- if num in dict:
- dict[num] += 1
- else:
- dict[num] = 1
- print(dict)
- interval = 1 / size
- SH = 0
- for num in dict:
- HH = dict[num] * interval + SH
- dict_int[num] = (SH, HH)
- SH = HH
- print(dict_int)
- L = 0
- H = 1
- for num in file:
- IN = (L + (dict_int[num][0]*(H-L)), L + (dict_int[num][1]*(H-L)))
- L = IN[0]
- H = IN[1]
- print(IN)
- if round(L + 0.0000001, 7) < H:
- dict[num] = round(L + 0.0000001, 7)
- else:
- dict[num] = round(H, 7)
- print(dict)
- def decompress(list):
- L = 0
- H = 1
- for num in list:
- K = ((num[1] - L) / (H - L))
- def readbin(filename):
- numbers = list()
- try:
- with open(filename, 'rb') as f:
- a = f.read(1)
- while a != b"":
- numbers.append(struct.unpack("B", a)[0])
- a = f.read(1)
- return numbers
- except Exception as error:
- print("chyba " + error.__str__())
- if __name__ == '__main__':
- compress(readbin("Cv07_Aritm_data.bin"))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement