1

I currently have a matrix that is 6x3 containing different probabilities.

My rows in this case has 3 values, corresponding to the probability of my sample ending up belonging to a certain class.

What I'm trying to do is to get every of the 3 different classes for my 6 samples. I'm worried that I might end up with duplicates.

I've noticed that every element in lista contains 6 values. Is there a simple way for me to get rid of possible duplicates ?

for combination in itertools.product(*probability):
    q1 = np.prod((combination))
    lista.append(q1)
    print(combination)
    i = i+1
print(i)
print(np.sum(lista))

Thanks in advance!

Nordle
  • 2,915
  • 3
  • 16
  • 34
A.Maine
  • 117
  • 9

1 Answers1

5

Using set(lista) will remove any duplicate values

Example:

lista = [1,2,3,4,1,2]
new_list = set(lista)
print(new_list)

Output:

{1, 2, 3, 4}

Edit: As per your comment, use itertools and groupby() to remove duplicate lists within a list as such;

import itertools

lista = [[1,2,3], [1,2,3], [3,4,5]]
new_list = list(k for k,_ in itertools.groupby(lista))
print(new_list)

Output:

[[1, 2, 3], [3, 4, 5]]
Nordle
  • 2,915
  • 3
  • 16
  • 34
  • Got one question, it seems like this removes items that are the same, but I have a list containing multiple values, for example list((0,1 , 0,2 , 0,3 , 0,4 , 0,5 , 0,6),(0.1, 0.2 , 0.3 , 0.4 , 0.5 , 0. 7). I do not wish it to remove these objects, only that it removes two lists that are identical, not the objects in it. – A.Maine Dec 13 '18 at 12:27
  • @A.Maine I've added another suggestion based on what you're asking, hope it helps. – Nordle Dec 13 '18 at 12:34
  • Thanks a lot for this implementation! Will accept answer as soon as I can – A.Maine Dec 13 '18 at 12:37