Find the unique elements of an array.
Parameters: | ar1 : array_like
return_index : bool, optional
return_inverse : bool, optional
|
---|---|
Returns: | unique : ndarray
unique_indices : ndarray, optional
unique_inverse : ndarray, optional
|
See also
Examples
>>> np.unique1d([1, 1, 2, 2, 3, 3])
array([1, 2, 3])
>>> a = np.array([[1, 1], [2, 3]])
>>> np.unique1d(a)
array([1, 2, 3])
Reconstruct the input from unique values:
>>> np.unique1d([1,2,6,4,2,3,2], return_index=True)
>>> x = [1,2,6,4,2,3,2]
>>> u, i = np.unique1d(x, return_inverse=True)
>>> u
array([1, 2, 3, 4, 6])
>>> i
array([0, 1, 4, 3, 1, 2, 1])
>>> [u[p] for p in i]
[1, 2, 6, 4, 2, 3, 2]