Find the unique elements of an array. Returns the sorted unique elements of an array. There are three optional outputs in addition to the unique elements: * the indices of the input array that give the unique values * the indices of the unique array that reconstruct the input
(ar, return_index=False, return_inverse=False,
return_counts=False, axis=None, *, equal_nan=True,
sorted=True)
| 144 | |
| 145 | @array_function_dispatch(_unique_dispatcher) |
| 146 | def unique(ar, return_index=False, return_inverse=False, |
| 147 | return_counts=False, axis=None, *, equal_nan=True, |
| 148 | sorted=True): |
| 149 | """ |
| 150 | Find the unique elements of an array. |
| 151 | |
| 152 | Returns the sorted unique elements of an array. There are three optional |
| 153 | outputs in addition to the unique elements: |
| 154 | |
| 155 | * the indices of the input array that give the unique values |
| 156 | * the indices of the unique array that reconstruct the input array |
| 157 | * the number of times each unique value comes up in the input array |
| 158 | |
| 159 | Parameters |
| 160 | ---------- |
| 161 | ar : array_like |
| 162 | Input array. Unless `axis` is specified, this will be flattened if it |
| 163 | is not already 1-D. |
| 164 | return_index : bool, optional |
| 165 | If True, also return the indices of `ar` (along the specified axis, |
| 166 | if provided, or in the flattened array) that result in the unique array. |
| 167 | return_inverse : bool, optional |
| 168 | If True, also return the indices of the unique array (for the specified |
| 169 | axis, if provided) that can be used to reconstruct `ar`. |
| 170 | return_counts : bool, optional |
| 171 | If True, also return the number of times each unique item appears |
| 172 | in `ar`. |
| 173 | axis : int or None, optional |
| 174 | The axis to operate on. If None, `ar` will be flattened. If an integer, |
| 175 | the subarrays indexed by the given axis will be flattened and treated |
| 176 | as the elements of a 1-D array with the dimension of the given axis, |
| 177 | see the notes for more details. Object arrays or structured arrays |
| 178 | that contain objects are not supported if the `axis` kwarg is used. The |
| 179 | default is None. |
| 180 | |
| 181 | equal_nan : bool, optional |
| 182 | If True, collapses multiple NaN values in the return array into one. |
| 183 | |
| 184 | .. versionadded:: 1.24 |
| 185 | |
| 186 | sorted : bool, optional |
| 187 | If True, the unique elements are sorted. Elements may be sorted in |
| 188 | practice even if ``sorted=False``, but this could change without |
| 189 | notice. |
| 190 | |
| 191 | .. versionadded:: 2.3 |
| 192 | |
| 193 | Returns |
| 194 | ------- |
| 195 | unique : ndarray |
| 196 | The sorted unique values. |
| 197 | unique_indices : ndarray, optional |
| 198 | The indices of the first occurrences of the unique values in the |
| 199 | original array. Only provided if `return_index` is True. |
| 200 | unique_inverse : ndarray, optional |
| 201 | The indices to reconstruct the original array from the |
| 202 | unique array. Only provided if `return_inverse` is True. |
| 203 | unique_counts : ndarray, optional |
searching dependent graphs…