uniq¶
- pydl.uniq(x, index=None)[source]¶
Replicates the IDL
UNIQ()function.Returns the subscripts of the unique elements of an array. The elements must actually be sorted before being passed to this function. This can be done by sorting
xexplicitly or by passing the array subscripts that sortxas a second parameter.- Parameters:
- xarray-like
Search this array for unique items.
- indexarray-like, optional
This array provides the array subscripts that sort
x.
- Returns:
- array-like
The subscripts of
xthat are the unique elements ofx.
Notes
Given a sorted array, and assuming that there is a set of adjacent identical items,
uniq()will return the subscript of the last unique item. This charming feature is retained for reproducibility.References
https://www.nv5geospatialsoftware.com/docs/uniq.html
Examples
>>> import numpy as np >>> from pydl import uniq >>> data = np.array([ 1, 2, 3, 1, 5, 6, 1, 7, 3, 2, 5, 9, 11, 1 ]) >>> print(uniq(np.sort(data))) [ 3 5 7 9 10 11 12 13]