numpy unique without sort
numpy, python
Solution
You can do this with the `return_index` parameter:
>>> import numpy as np
>>> a = [4,2,1,3,1,2,3,4]
>>> np.unique(a)
array([1, 2, 3, 4])
>>> indexes = np.unique(a, return_index=True)[1]
>>> [a[index] for index in sorted(indexes)]
[4, 2, 1, 3]
Problem
How can I use numpy unique without sorting the result but just in the order they appear in the sequence? Something like this? `a = [4,2,1,3,1,2,3,4]` `np.unique(a) = [4,2,1,3]` rather than `np.unique(a) = [1,2,3,4]` Use naive solution should be fine to write a simple function. But as I need to do this multiple times, are there any fast and neat way to do this?