{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"raw","source":"**feel free to use the function and please upvote**","metadata":{}},{"cell_type":"code","source":"# It takes annotation as an input and decodes the data into a list of integers\ndef RLD(s):\n    s=s.split(\" \")\n    ans=[]\n    i=0\n    while i<len(s):\n        j=0\n        n=int(s[i])\n        while j<int(s[i+1]):\n            ans.append(int(n))\n            n=n+1\n            j=j+1\n        i=i+2\n    return ans","metadata":{"execution":{"iopub.status.busy":"2021-10-16T12:26:04.619627Z","iopub.execute_input":"2021-10-16T12:26:04.619912Z","iopub.status.idle":"2021-10-16T12:26:04.626589Z","shell.execute_reply.started":"2021-10-16T12:26:04.619883Z","shell.execute_reply":"2021-10-16T12:26:04.625932Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Run length encoding and decoding**\n\nRun length encoding is a way of compressing information without the loss of any information.","metadata":{}},{"cell_type":"markdown","source":"consider the list of numbers,\n\nl=[ 1 , 2 , 3 , 4 , 5 ,15 , 16 , 17 , 18 ]\n\nAs we can see it is a sequential data, In such cases instead of wasting space for every element we can say\n> *start from **1** and increment it **4** times* and \n*start from **15** and increment it **3** times*\n","metadata":{}},{"cell_type":"markdown","source":"The Above sentence can be encoded in Run length as **\"1 4 15 3\"**\n\nSample code for usage of the function explained below.","metadata":{}},{"cell_type":"code","source":"import numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\ntrain=pd.read_csv(\"../input/sartorius-cell-instance-segmentation/train.csv\")","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","_kg_hide-output":true,"execution":{"iopub.status.busy":"2021-10-16T12:26:04.628279Z","iopub.execute_input":"2021-10-16T12:26:04.628682Z","iopub.status.idle":"2021-10-16T12:26:06.255609Z","shell.execute_reply.started":"2021-10-16T12:26:04.628633Z","shell.execute_reply":"2021-10-16T12:26:06.254617Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#giving annotation as an input\n\na=RLD(train[\"annotation\"][0])\n\na\n\n#Upvote","metadata":{"execution":{"iopub.status.busy":"2021-10-16T12:26:06.256946Z","iopub.execute_input":"2021-10-16T12:26:06.257284Z","iopub.status.idle":"2021-10-16T12:26:06.291205Z","shell.execute_reply.started":"2021-10-16T12:26:06.257241Z","shell.execute_reply":"2021-10-16T12:26:06.2891Z"},"trusted":true},"execution_count":null,"outputs":[]}]}