mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-10 12:39:13 +08:00
Ensure array input to unique_rows is contiguous
This commit is contained in:
@@ -30,6 +30,11 @@ def unique_rows(ar):
|
||||
if ar.ndim != 2:
|
||||
raise ValueError("unique_rows() only makes sense for 2D arrays, "
|
||||
"got %dd" % ar.ndim)
|
||||
# the view in the next line only works if the array is C-contiguous
|
||||
ar = np.ascontiguousarray(ar)
|
||||
# np.unique() finds identical items in a raveled array. To make it
|
||||
# see each row as a single item, we create a view of each row as a
|
||||
# byte string of length itemsize times number of columns in `ar`
|
||||
ar_row_view = ar.view('|S%d' % (ar.itemsize * ar.shape[1]))
|
||||
_, unique_row_indices = np.unique(ar_row_view, return_index=True)
|
||||
ar_out = ar[unique_row_indices]
|
||||
|
||||
Reference in New Issue
Block a user