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



我们有两个列表,每个列表包含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]

这些列表彼此对应;索引列表Mfccs";具有实际值;索引列表";包含这些值的参数。

我们想提取";索引列表";。但有时我们可以有两个或更多的重复,三元组。。。如在示例中那样。在示例的情况下,我们有四个重复(0、5、1和9(,并且希望提取并比较"0"中的相应值;索引列表Mfccs";像这样:(0.640495,0.4822588,0.6523488,0.5423001,0.85711163,0.724612,0.9696293,0.97258127(为了选择最大的一个,这里是0.97258127。

注意:例如,如果有一个三重参数和两个重复参数,则选择的值将是三重参数的三个值中的最大值。如果有四重或五重的论点,也是如此。因此,产量越高,优先级就越高。

好的-如果你只想从多次索引中得到最大的数字,请使用以下方法:

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) 

最新更新