根据来自另一个列表的参数提取和比较列表的值

Extract and compare values of a list depending on their arguments which come from another list

我们有 2 个列表,每个列表包含 10 个值,您可以在此处查看示例: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]

列表相互对应,“Index list Mfccs”有实际值,“Index list”包含这些值的参数。

我们想提取“索引列表”中最常出现的参数。但有时我们可以有两个或多个重复,三胞胎......如示例所示。在这个例子中,我们有四个重复项(0、5、1 和 9),并且想要提取和比较“Index list Mfccs”中的相应值,如下所示:(0.640495, 0.4822588, 0.6523488, 0.5423001, 0.85711163, 0.724612, 0.9696293, 0.97258127) 为了选最大的,这里0.97258127.

注意: 例如,如果有一个三重参数和 2 个重复参数,则选择的值将是三重参数的三个值中的最大值。如果存在四倍或五倍参数,则相同。所以,冗余度越高,优先级越高。

好的 - 如果您只想要多次索引的最大数字,请使用以下内容:

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)

更新: 根据您的附加要求优先考虑发生的幅度,解决方案如下(相同幅度的指数将考虑所有值)

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)

这是另一个应该有效的解决方案:

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)