@@ -135,16 +135,18 @@ def unique(ar, return_index=False, return_inverse=False,
135
135
return_counts : bool, optional
136
136
If True, also return the number of times each unique item appears
137
137
in `ar`.
138
+
138
139
.. versionadded:: 1.9.0
139
- axis : int or None, optional
140
- The axis to operate on. If None, `ar` will be flattened beforehand.
141
- Otherwise, duplicate items will be removed along the provided axis,
142
- with all the other axes belonging to the each of the unique elements.
143
- Object arrays or structured arrays that contain objects are not
144
- supported if the `axis` kwarg is used.
145
- .. versionadded:: 1.13.0
146
140
141
+ axis : int or None, optional
142
+ The axis to operate on. If None, `ar` will be flattened. If an integer,
143
+ the subarrays indexed by the given axis will be flattened and treated
144
+ as the elements of a 1-D array with the dimension of the given axis,
145
+ see the notes for more details. Object arrays or structured arrays
146
+ that contain objects are not supported if the `axis` kwarg is used. The
147
+ default is None.
147
148
149
+ .. versionadded:: 1.13.0
148
150
149
151
Returns
150
152
-------
@@ -166,6 +168,17 @@ def unique(ar, return_index=False, return_inverse=False,
166
168
numpy.lib.arraysetops : Module with a number of other functions for
167
169
performing set operations on arrays.
168
170
171
+ Notes
172
+ -----
173
+ When an axis is specified the subarrays indexed by the axis are sorted.
174
+ This is done by making the specified axis the first dimension of the array
175
+ and then flattening the subarrays in C order. The flattened subarrays are
176
+ then viewed as a structured type with each element given a label, with the
177
+ effect that we end up with a 1-D array of structured types that can be
178
+ treated in the same way as any other 1-D array. The result is that the
179
+ flattened subarrays are sorted in lexicographic order starting with the
180
+ first element.
181
+
169
182
Examples
170
183
--------
171
184
>>> np.unique([1, 1, 2, 2, 3, 3])
@@ -217,14 +230,7 @@ def unique(ar, return_index=False, return_inverse=False,
217
230
ar = ar .reshape (orig_shape [0 ], - 1 )
218
231
ar = np .ascontiguousarray (ar )
219
232
220
- if ar .dtype .char in (np .typecodes ['AllInteger' ] +
221
- np .typecodes ['Datetime' ] + 'S' ):
222
- # Optimization: Creating a view of your data with a np.void data type of
223
- # size the number of bytes in a full row. Handles any type where items
224
- # have a unique binary representation, i.e. 0 is only 0, not +0 and -0.
225
- dtype = np .dtype ((np .void , ar .dtype .itemsize * ar .shape [1 ]))
226
- else :
227
- dtype = [('f{i}' .format (i = i ), ar .dtype ) for i in range (ar .shape [1 ])]
233
+ dtype = [('f{i}' .format (i = i ), ar .dtype ) for i in range (ar .shape [1 ])]
228
234
229
235
try :
230
236
consolidated = ar .view (dtype )
0 commit comments