Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE REQUEST] numpy.unique #494

Open
water5 opened this issue Jan 23, 2022 · 4 comments
Open

[FEATURE REQUEST] numpy.unique #494

water5 opened this issue Jan 23, 2022 · 4 comments
Labels
enhancement New feature or request low-priority low-priority bug, to be fixed, when everything else works

Comments

@water5
Copy link

water5 commented Jan 23, 2022

https://numpy.org/doc/stable/reference/generated/numpy.unique.html

@water5 water5 added the enhancement New feature or request label Jan 23, 2022
@v923z
Copy link
Owner

v923z commented Jan 23, 2022

While it is not the most performant way, I think you can already get this functionality by

a = np.array(...)
set(a.tolist())

@water5 water5 closed this as completed Jan 24, 2022
@water5 water5 reopened this Jan 24, 2022
@v923z v923z added the low-priority low-priority bug, to be fixed, when everything else works label Jan 24, 2022
@water5
Copy link
Author

water5 commented Jan 24, 2022

But set not support ndarray to list result.

a = np.arange(9).reshape((3, 3))
a

array([[0, 1, 2],
[3, 4, 5],
[6, 7, 8]], dtype=int16)

a = a.tolist()
a

[[0, 1, 2], [3, 4, 5], [6, 7, 8]]

set(a)

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported type for __hash__: 'list'

Only support 1D:

a = np.arange(9)
a

array([0, 1, 2, 3, 4, 5, 6, 7, 8], dtype=int16)

set(a)

{0, 1, 2, 3, 4, 5, 6, 7, 8}

@water5
Copy link
Author

water5 commented Jan 24, 2022

Although we can do set operation after numpy.reshape:

a = a.reshape((9, ))
set(a)
a = a.reshape((3, 3))

But the return_index parameter result will pointless.

@v923z
Copy link
Owner

v923z commented Jan 24, 2022

I am trying to understand in what situation this function would be required.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request low-priority low-priority bug, to be fixed, when everything else works
Projects
None yet
Development

No branches or pull requests

2 participants