Feature request numpy.unique axis=0
See original GitHub issueFeature request
I want to go from
a = np.array([[1, 1, 1, 0, 0, 0],
[0, 1, 1, 1, 0, 0],
[0, 1, 1, 1, 0, 0],
[1, 1, 1, 0, 0, 0],
[1, 1, 1, 1, 1, 0]])
to
array([[1, 1, 1, 0, 0, 0],
[0, 1, 1, 1, 0, 0],
[1, 1, 1, 1, 1, 0]])
Using numpy I would use
unique_rows = np.unique(a, axis=0)
however, the axis parameter is not supported yet. I tried some workarounds based on this SO question, but I havn’t figured out a sollution yet.
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
Numpy unique 2D sub-array [duplicate] - Stack Overflow
This is a new feature in the upcoming 1.13, as np.unique(a, axis=0) . You could simply copy the new implementation and use it...
Read more >numpy.unique — NumPy v1.25.dev0 Manual
Returns the sorted unique elements of an array. There are three optional outputs in addition to the unique elements: the indices of the...
Read more >Numpy Unique, Explained - Sharp Sight
Now that we have our array, let's get the unique rows and unique columns. To get the unique rows, we set axis =...
Read more >np.unique along a axis numpy Code Example - Code Grepper
As of NumPy 1.13, one can simply choose the axis for selection of unique values ... can do: import numpy as np unique_rows...
Read more >Supported NumPy features - Numba
NumPy arrays provide an efficient storage method for homogeneous sets of data. NumPy dtypes provide type information useful when compiling, and the regular, ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I wrote this a while back, which gets the job done.
Someday, when I figure out how to avoid writing 8 different implementations for various combinations of np.uniques returns, I’ll contribute this back into numba.
Many thanks for the request! A runnable MWR to test for the feature in future is:
which presently gives: