SHARE
TWEET

Untitled

a guest Oct 21st, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import numpy as np
  2.  
  3. def encode(a):
  4.     result = []
  5.     if a:
  6.         current = a.pop(0)
  7.         counter = 1
  8.         for i in a:
  9.             if i == current:
  10.                 counter += 1
  11.             else:
  12.                 result.append((counter, current))
  13.                 current = i
  14.                 counter = 1
  15.         result.append((counter, current))
  16.     return result
  17.  
  18. X = np.array([1, 2, 2, 3, 3, 1, 1, 5, 5, 2, 3, 3])
  19. num = np_encode(X)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top