Issue
In Python numpy: indexes returned by np.unique(a, return_index=True) - will ALWAYS come in natural order ? I.e. we get the FIRST occurrence of element as first index ? Or the order can be arbitrary ?
In most examples I tried - the order is natural, but just want to confirm it is ALWAYS the case ?
Example:
a = np.array(['a', 'b', 'b', 'c', 'a'])
u, indices = np.unique(a, return_index=True)
array([0, 1, 3])
Solution
From the function's documentation of return values:
unique_indices ndarray, optional
The indices of the first occurrences of the unique values in the original array. Only provided if return_index is True.
So yes, you get first occurrence of elements.
Answered By - Andrej Kesely
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.