python 平均值 最大值 最小值_在python中获取列表中索引的最大值、最小值和平均值...

我的代码是遗传算法。我的问题是:

我要回报最好的个人,最差的和一般的。我要做的就是列表的索引。示例:最佳值=高比率更多。最差值=最小索引。我不知道怎么做。这是我的代码:def selecciona_mejor_peor_medio(self, population):

list = []

cont = 0

arff = self.arff_reader_class

attributes_list = []

attributes_counter = []

for element in list:

if element[len(element)-1] in arff.consequences:

temporal_rule = element

# We take the first attribute

for attribute in element:

# Seek other sets that start with the same item and group them into lists.

# Subsequently removed from the initial list to avoid repeating values

for rule_list in self.population_my_method:

for rule in rule_list:

cont_attribute = 0

for rule_attribute in rule:

if rule_attribute == attribute:

cont_attribute += 1

if cont_attribute == len(element):

cont += 1

attributes_counter.append(cont)

# Find the index of the highest value, medium and low

peor = attributes_counter.index(min(attributes_counter))

mejor = attributes_counter.index(max(attributes_counter))

index, value = max(enumerate(list), key=operator.itemgetter(1))

# With the rates you get the values ​​at the population

if mejor > list[cont]:

return mejor

elif peor < list[cont]:

return peor

else:

return list[cont]

我不知道如何获取和返回这些值。希望你能帮助我。非常感谢

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值