Implement a unique
function returning only the unique values in a vector.
#940
Labels
idea
Proposition of an idea and opening an issue to discuss it
Motivation
Recently, I've run into the problem of extracting unique values in a vector (of any integer, real or complex type or possibly even character). Consider for instance the following vector
x = [1, 2, 3, 3, 4]
. What I'd need is a function takingx
as input and returning the vectory = [1, 2, 3, 4]
as output. The interface for a real-valued vector could be as simple asThe output vector could be sorted or not, depending on the user's choice. I know that there are no Fortran intrinsic functions for that purpose, but I ain't sure something like that is already available in
stdlib
. If I'm wrong, could anyone point me to the correct function?Prior Art
unique
function whose description is available here.set
function taking as input alist
and returning only the unique elements of this list.np.unique
whose description is available here.Additional Information
Both Matlab and Numpy's implementations cover a relatively large set of cases (1D-array, multidimensional arrays, different types, etc) and return values (the unique elements, the corresponding indices, indices to the reconstruct the original array from this unique set, etc).
I don't know if absolutely all these cases need to be covered (at least as a starting point). I would probably recommend to start with the simplest ones (i.e. only input vectors and output vector with the unique elements) as these are probably the most common situations where a
unique
function might be needed. That would includeinteger
,real
,complex
andcharacter
1D-arrays.The text was updated successfully, but these errors were encountered: