python - 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!
解决方案
您可以使用 Numpy 数组。它们比 Python 中的列表更快。由于您非常关心速度,Numpy 可能是您的最佳选择
推荐阅读
- php - php分段文件上传以数组分隔
- r - 将嵌套循环与嵌套列表一起使用
- android - 当我的朋友下载时,我的应用程序没有徽标
- c++ - 为什么 RTSP 接收形式在 2 种情况下不同
- azure-service-fabric - 在比配置的 VM Scaleset 节点更小的节点上部署的 Service Fabric 无状态服务上获取 502 http 状态代码
- ssis - 2 步身份验证 C# 通过 SSIS 2010 访问 JSON API
- javascript - 确定元素覆盖了多少视口(IntersectionObserver)
- python - 字符串中的 Python \0 后跟数字的行为不一致
- android - 如何仅使用文本创建水平回收视图?
- forms - 翻译 EXT:TYPO3 8.7 中的表单验证器