Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.29 KB | None | 0 0
  1. import struct
  2.  
  3.  
  4. def compress(file):
  5.     print(file)
  6.     size = len(file)
  7.     dict = {}
  8.     dict_int = {}
  9.     list = sorted(file)
  10.     for num in list:
  11.         if num in dict:
  12.             dict[num] += 1
  13.         else:
  14.             dict[num] = 1
  15.     print(dict)
  16.  
  17.     interval = 1 / size
  18.     SH = 0
  19.     for num in dict:
  20.         HH = dict[num] * interval + SH
  21.         dict_int[num] = (SH, HH)
  22.         SH = HH
  23.  
  24.     print(dict_int)
  25.     L = 0
  26.     H = 1
  27.     for num in file:
  28.         IN = (L + (dict_int[num][0]*(H-L)), L + (dict_int[num][1]*(H-L)))
  29.         L = IN[0]
  30.         H = IN[1]
  31.         print(IN)
  32.         if round(L + 0.0000001, 7) < H:
  33.             dict[num] = round(L + 0.0000001, 7)
  34.         else:
  35.             dict[num] = round(H, 7)
  36.     print(dict)
  37.  
  38.  
  39. def decompress(list):
  40.     L = 0
  41.     H = 1
  42.     for num in list:
  43.         K = ((num[1] - L) / (H - L))
  44.  
  45.  
  46.  
  47. def readbin(filename):
  48.     numbers = list()
  49.     try:
  50.         with open(filename, 'rb') as f:
  51.             a = f.read(1)
  52.             while a != b"":
  53.                 numbers.append(struct.unpack("B", a)[0])
  54.                 a = f.read(1)
  55.         return numbers
  56.  
  57.     except Exception as error:
  58.         print("chyba " + error.__str__())
  59.  
  60.  
  61. if __name__ == '__main__':
  62.     compress(readbin("Cv07_Aritm_data.bin"))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement