开发者

Memory error in np.hstack()

开发者 https://www.devze.com 2023-03-04 22:37 出处:网络
I am trying to execute this code: for i in Fil: for k in DatArr: a = np.zeros(0) for j in Bui: a = np.hstack([a,DatDifCor[k][i,j]])

I am trying to execute this code:

for i in Fil:  
    for k in DatArr:  
        a = np.zeros(0)  
        for j in Bui:  
            a = np.hstack([a,DatDifCor[k][i,j]])  
        DatDifPlt[k].update({i:a})  

But it gives me this error:

Traceback (most recent call last):  
  File "<ipython开发者_如何学运维 console>", line 5, in <module>  
  File "C:\Python26\lib\site-packages\numpy\core\shape_base.py", line 258, in hstack  
    return _nx.concatenate(map(atleast_1d,tup),1)  
MemoryError

I thought it was due to a lack of RAM memory in the first place, but then I tried in on a PC with 48 Gb of RAM and it gave the same error. Have I reached the maximum size for a NumPy.array?


A MemoryError always means that an attempt to allocate memory failed. Trying to create an array bigger than the maximum array size results in a ValueError:

>>> a = numpy.arange(500000000)
>>> numpy.hstack((a, a))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/pymodules/python2.6/numpy/core/shape_base.py", line 258, in hstack
    return _nx.concatenate(map(atleast_1d,tup),1)
ValueError: array is too big.

Note that 48 GB are also a finite ammount of memory, and that your operating system (or even the hardware platform) might restrict the size of a single process to 4 GB.

0

精彩评论

暂无评论...
验证码 换一张
取 消