Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- def encode(a):
- result = []
- if a:
- current = a.pop(0)
- counter = 1
- for i in a:
- if i == current:
- counter += 1
- else:
- result.append((counter, current))
- current = i
- counter = 1
- result.append((counter, current))
- return result
- X = np.array([1, 2, 2, 3, 3, 1, 1, 5, 5, 2, 3, 3])
- num = np_encode(X)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement