i am trying to write a code which takes input as below and then find the highest and average where f(x)= number of ones in x .

['00111110011001010011', '01111101001101110010', '01100110111110000000', '01101101100111001001']
def fitness(genome):
    return reduce((lambda x, y: int(x) + int(y)), list(genome))

# reference : https://www.geeksforgeeks.org/reduce-in-python/

def evaluateFitness(population):
    sums = list(map(lambda x: fitness(x), population))
    return [max(sums), sum(sums) / len(population)]

the above function works well. i want to know if there is any library in numpy or scipy which can do the same or pygad.basically trying to find alternate option to achieve the same result.

0

There are 0 best solutions below