首页 > 解决方案 > How can I change the data type to run the program faster?

问题描述

I write a genetic algorithm and I represent the population as a list of 50 chromosomes and every chromosome is a number of 20 string bytes. In order to understand I write an example:

[['111000110','110000110','011000110','001000110'],
 [''111001010','111110110','111001110','111000100']]

The operations with strings are time consuming and I want to find another way to represent the population.Any suggestions? Thank you!

标签: pythongenetic-algorithm

解决方案


您可以使用 Numpy 数组。它们比 Python 中的列表更快。由于您非常关心速度,Numpy 可能是您的最佳选择


推荐阅读