micropython-ulab
micropython-ulab copied to clipboard
[FEATURE REQUEST] numpy.unique
While it is not the most performant way, I think you can already get this functionality by
a = np.array(...)
set(a.tolist())
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}
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.
I am trying to understand in what situation this function would be required.