data = np.array(['b', 'b', 'b', 'a', 'a', 'a', 'a', 'c', 'c', 'd', 'd', 'd'])
_, ind = np.unique(data, return_index=True)
unqs = data[np.sort(ind)]
data_id = dict(zip(unqs, np.arange(data.size)))
num = np.array([data_id[datum] for datum in data])
numpy replace groups of elements with integers incrementally