Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you remove duplicate values in array in Python?

I have an array where each element is the mean of a set of random numbers. I want to be able to remove duplicate values in this array. How would I go about doing this?

So far I have tried:

for i in range(len(array)):
    
    for j in array:

        if array[i] == j:

and then some operation to remove the element from the array. However, this will just remove every instance of every duplicated element.

like image 993
Thomas Avatar asked Jun 09 '26 15:06

Thomas


1 Answers

You could simply use np.unique():

unique_values = np.unique(array)
like image 63
Hiibb Avatar answered Jun 11 '26 05:06

Hiibb