order = array.argsort(kind='mergesort')
array = array[order]
diff = array[1:] != array[:-1]
if orderby == 'first':
    diff = np.concatenate([[True], diff])
elif orderby == 'last':
    diff = np.concatenate([diff, [True]])
else:
    raise ValueError
uniq = array[diff]
index = order[diff]
return uniq[index.argsort()]
numpy уникальный без сортировки