【问题标题】:How to randomly alter an array based on an if statement as if mutating a gene in a genetic algorithm?如何根据 if 语句随机更改数组,就像在遗传算法中突变基因一样?
【发布时间】:2018-05-12 15:33:46
【问题描述】:

mutation_rate=.05 和 current_pop 是一个数组。如何使这个 if 语句随机更改数组中的值?这是遗传算法中的突变。感谢您的帮助!

    for i in range(len(current_pop)):
        r= np.random.rand() 
        if r < mutation_rate: 

    return new_array

`

【问题讨论】:

    标签: arrays python-3.x random genetic-algorithm mutation


    【解决方案1】:

    current_pop[i] = random.randint(min_val, max_val)

    您应该定义最小值和最大值。

    【讨论】:

      猜你喜欢
      • 2017-09-06
      • 2016-11-04
      • 2017-03-30
      • 1970-01-01
      • 1970-01-01
      • 2019-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多