python - 'list' 对象在 Python 中是不可调用的错误
问题描述
我正在研究遗传算法问题。我根据他们的健康选择了一些有能力的人。现在我正在尝试在个体之间进行繁殖以产生下一代。
def crossover(parent1,parent2):
parent1=np.random.randint(0,100,20)
parent2=np.random.randint(0,100,20)
child1=[]
child2=[]
crossover_point=int(np.random.random()*len(parent1))
for i in range(crossover_point+1):
child1.append(parent1[i])
child2.append(parent2[i])
temp=i
for i in range(temp+1,len(parent1)):
child1.append(parent2[i])
child2.append(parent1[i])
return child1,child2
def breed_population(selection_result):
k=len(selection_result)//2
children=[]
for i in range(k):
child=crossover(selection_result[i],selection_result(k-i-1))
children.append(child)
return children
selection_result=[10, 8, 19, 10, 5, 1, 11, 14, 17, 8, 16, 16, 11, 8, 17, 13, 11, 10, 8, 11]
p=breed_population(selection_result)
现在,我收到以下错误。
TypeError Traceback (most recent call last)
<ipython-input-2-d2718835d6df> in <module>
24 return children
25 selection_result=[10, 8, 19, 10, 5, 1, 11, 14, 17, 8, 16, 16, 11, 8, 17, 13, 11, 10, 8, 11]
---> 26 p=breed_population(selection_result)
<ipython-input-2-d2718835d6df> in breed_population(selection_result)
19 children=[]
20 for i in range(k):
---> 21 child=crossover(selection_result[i],selection_result(k-i-1))
22 children.append(child)
23
TypeError: 'list' object is not callable
解决方案
推荐阅读
- java - com.sun.mail.smtp.SMTPSendFailedException: 550 5.2.125 发件人已超过允许发送的最大邮件数
- javascript - 无法使用 ES 6 模块导入语句使用 css-loader
- c++ - 使用 SIR 模型的疾病爆发模拟
- vuejs2 - 何时创建组件?- Vue.js
- visual-studio-code - 为什么在 vscode 的扩展内部未定义 stream.pipeline?
- python - 如何断言根据条件过滤的熊猫数据框为真
- database - DB2 中的事件监视器记录从 VPN 在创建事件的同一台服务器上运行的查询的详细信息?
- mysql - Rails 迁移:在不更改类型的情况下向列添加注释
- r - 有没有办法总结我的问卷数据以显示每个问题的每个响应的数量?
- firebase - 为什么 firebase phone auth 需要在 Xcode 中注册自定义 URL 方案?