micropython-ulab icon indicating copy to clipboard operation
micropython-ulab copied to clipboard

[FEATURE REQUEST] numpy.unique

Open water5 opened this issue 3 years ago • 4 comments

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

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

v923z avatar Jan 23 '22 20:01 v923z

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 avatar Jan 24 '22 19:01 water5

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.

water5 avatar Jan 24 '22 20:01 water5

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

v923z avatar Jan 24 '22 20:01 v923z