[英]Memory Error in Python despite having sufficient RAM
from __future__ import division
import scipy.io
import numpy as np
import math
from math import sin
from math import cos
mat = np.zeros((1024,1024,360 ),dtype=np.float32)
x = scipy.io.loadmat('/home/prakriti/Project/A.mat')
A = np.array((x.values()))
mat[:,:,0:120] = A[0][:,:,:]
del x
del A
y = scipy.io.loadmat('/home/prakriti/Project/B.mat')
B = np.array((y.values()))
mat[:,:,120:240] = B[0][:,:,:]
del y
del B
z = scipy.io.loadmat('/home/prakriti/Project/C.mat')
C = np.array((z.values()))
mat[:,:,240:360] = C[0][:,:,:]
del z
del C
s = np.linspace(0,1023,1024)
v = np.linspace(0,1023,1024)
ss,vv = np.meshgrid(s,v)
zz = ss**2 + vv**2
print zz
I have been getting the following error for this. 我已经收到以下错误。 Can anyone explain me what is the problem here?
谁能解释给我这是什么问题? I am trying to make a 3-D matrix mat with data that is available to me.
我正在尝试使用可用的数据制作3-D矩阵垫。 I have 49GB of RAM available.
我有49GB的RAM。 Why do I still get memory error?
为什么仍然出现内存错误?
Traceback (most recent call last):
File "/home/prakriti/Project/fdk_new.py", line 11, in <module>
x = scipy.io.loadmat('/home/prakriti/Project/A.mat')
File "/usr/lib/python2.7/dist-packages/scipy/io/matlab/mio.py", line 152, in loadmat
matfile_dict = MR.get_variables(variable_names)
File "/usr/lib/python2.7/dist-packages/scipy/io/matlab/mio5.py", line 270, in get_variables
hdr, next_position = self.read_var_header()
File "/usr/lib/python2.7/dist-packages/scipy/io/matlab/mio5.py", line 223, in read_var_header
stream = BytesIO(dcor.decompress(data))
MemoryError
Providing an answer because a comment would not format correctly. 提供答案,因为注释格式不正确。
Try not creating extra memory. 尝试不创建额外的内存。 The GIL takes a bit of time to release it.
GIL需要一些时间来释放它。
Instead of : 代替 :
x = scipy.io.loadmat('/home/prakriti/Project/A.mat')
A = np.array((x.values()))
mat[:,:,0:120] = A[0][:,:,:]
del x
del A
do: 做:
mat[:,:,0:120] = np.array((scipy.io.loadmat('/home/prakriti/Project/A.mat').values()))[0][:,:,:]
etc... 等等...
Otherwise, we need more info. 否则,我们需要更多信息。 Like the size of the
mat
files. 像
mat
文件的大小。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.