内存错误和列表限制? [英] Memory errors and list limits?

查看:71
本文介绍了内存错误和列表限制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于科学目的,我需要生成大的(非常大的)矩阵(马尔可夫链).我执行微积分,将其放入20301个元素的列表中(=矩阵的一行).我需要将所有这些数据存储在内存中以继续进行下一步的马尔可夫步骤,但是即使有必要,我也可以将它们存储在其他位置(例如文件),即使这会降低我的马尔可夫链的遍历速度.我的计算机(科学实验室):双氙气6个内核/12个线程,12GB内存,操作系统:win64

I need to produce large and big (very) matrices (Markov chains) for scientific purposes. I perform calculus that I put in a list of 20301 elements (=one row of my matrix). I need all those data in memory to proceed next Markov step but i can store them elsewhere (eg file) if needed even if it will slow my Markov chain walk-through. My computer (scientific lab): Bi-xenon 6 cores/12threads each, 12GB memory, OS: win64

  Traceback (most recent call last):
  File "my_file.py", line 247, in <module>
    ListTemp.append(calculus)
MemoryError

微积分结果示例:9.233747520008198e-102(是,超过1/9000)

Example of calculus results: 9.233747520008198e-102 (yes, it's over 1/9000)

存储第19766个元素时引发错误:

The error is raised when storing the 19766th element:

ListTemp[19766]
1.4509421012263216e-103

如果我走得更远

Traceback (most recent call last):
  File "<pyshell#21>", line 1, in <module>
    ListTemp[19767]
IndexError: list index out of range

因此,此列表在19767循环中发生了内存错误.

So this list had a memory error at the 19767 loop.

  1. 列表是否有内存限制? 是按列表限制"还是 每个脚本的全局限制"?

  1. Is there a memory limit to a list? Is it a "by-list limit" or a "global-per-script limit"?

如何绕过这些限制? 有什么想法吗?

How to bypass those limits? Any possibilites in mind?

使用numpy,python64是否有帮助?什么 内存限制了吗?什么 关于其他语言?

Will it help to use numpy, python64? What are the memory limits with them? What about other languages?

推荐答案

首先,请参见 Numpy,长数组存在问题

第二,唯一的实际限制来自您拥有的内存量以及系统存储内存引用的方式.没有每个列表的限制,因此Python会一直运行到内存耗尽为止.两种可能性:

Second, the only real limit comes from the amount of memory you have and how your system stores memory references. There is no per-list limit, so Python will go until it runs out of memory. Two possibilities:

  1. 如果您在较旧的OS上运行,或者在迫使进程使用有限数量的内存的操作系统上运行,则可能需要增加Python进程可以访问的内存数量.
  2. 使用分块将列表分开.例如,执行列表的前1000个元素,腌制并将其保存到磁盘,然后再进行下1000个.要使用它们,请一次释放一个块,以免耗尽内存.本质上,这是数据库用来处理超出RAM容量的数据的相同技术.

这篇关于内存错误和列表限制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆