-1

We have 2 lists of 10 values each one, as you can see an example here: Index list: [0, 5, 5, 6, 0, 1, 1, 8, 9, 9] Index list Mfccs : [0.640495, 0.4822588, 0.6523488, 0.74474275, 0.5423001, 0.85711163, 0.724612, 0.5099624, 0.9696293, 0.97258127]

The lists correspond to each other, "Index list Mfccs" has the real values and the "Index list" contains the arguments of these values.

We want to extract the most recurrent argument in "Index list". But sometimes we can have two or more duplications, triplets... as in the example. In the case of the example we have four duplications (0, 5, 1 and 9) and want to extract and compare the corresponding values in "Index list Mfccs" like this: (0.640495, 0.4822588, 0.6523488, 0.5423001, 0.85711163, 0.724612, 0.9696293, 0.97258127) in order to choose the biggest one, here 0.97258127.

Note: For example, if there is a tripled argument and 2 duplicates, the choosen value will be the max of the three values of the tripled argument. Same if there is a quadrupled or quintupled argument. So, higher the rodundance higher the priority.

A Khe
  • 73
  • 7
  • 1
    Please add the actual code instead of the picture. Also, please, add an example of the expected output. Your question is not super clear. Adding the expected output will help others understanding your question better. – alec_djinn Aug 06 '20 at 13:02
  • 1
    @alec_djinn Hi, sorry my english is so bad. I recently edited my request and hope that this time it's more comprehensible. – A Khe Aug 07 '20 at 07:52

2 Answers2

1

Ok - if you only want the largest number out of what is indexed multiple times use the following:

index_list = [0, 5, 5, 6, 0, 1, 1, 8, 9, 9]
index_list_mcfccs = [0.640495, 0.4822588, 0.6523488, 0.74474275, 0.5423001, 0.85711163, 0.724612, 0.5099624, 0.9696293, 0.97258127]

result_mcfccs = []

for idx, index in enumerate(index_list):
    if index_list.count(index) > 1:
        result_mcfccs.append(index_list_mcfccs[idx])
    
result = max(result_mcfccs)
print(result)

UPDATE: according to your additional requirements to consider the magnitude of occurrence as a priority, the solution would be as follows (same magnitude of indices will consider ALL values)

index_list = [0, 5, 5, 6, 0, 1, 1, 8, 9, 9]
index_list_mcfccs = [0.640495, 0.4822588, 0.6523488, 0.74474275, 0.5423001, 0.85711163, 0.724612, 0.5099624, 0.9696293, 0.97258127]

result_mcfccs = []

from collections import Counter

indices = list(map(lambda x: x[0], Counter(index_list).most_common()))
counts = list(map(lambda x: x[1], Counter(index_list).most_common()))

max_indices = [indices[i] for i, x in enumerate(counts) if x == max(counts)]

for idx, id in enumerate(index_list):
    if id in max_indices:
        result_mcfccs.append(index_list_mcfccs[idx])
    
result = max(result_mcfccs)
print(result)
EvilSmurf
  • 819
  • 1
  • 7
  • 21
  • EvilSmurf thanks for answering!. My question was not clear and the meaning can be understood in another way. Please check the question one more time i just edited it – A Khe Aug 06 '20 at 13:22
  • 1
    if this is working for you, please accept the answer – EvilSmurf Aug 07 '20 at 06:24
  • Hi !, of course i'll do it , but one more thing please. I updated the request one more time and i think the problem is more explicit now (please read "Note" part). Your answer works perfectly, but only in certain conditions. – A Khe Aug 07 '20 at 07:47
1

Here another solution that should work:

index_list = [1, 1, 1, 3, 5, 4, 7, 9, 9, 0]
index_list_mfccs = [0.640495, 0.4822588, 0.6523488, 0.74474275, 0.5423001, 0.85711163, 0.724612, 0.5099624, 0.9696293, 0.97258127]

histogram = dict((n, index_list.count(n)) for n in set(index_list))
result_mfccs = []

for m, n in enumerate(index_list):
    if index_list.count(n) == max (histogram.values()):
        result_mfccs.append(index_list_mfccs[m])
result = max(result_mfccs)
print(result) 
A Khe
  • 73
  • 7