2
我需要读取一个大2.5GB的文件。我用下面的syntx:有效地管理内存和python处理
import numpy as np
limit=4269*352*288*3
mat1=np.zeros(limit, dtype='uint8')
mat1=np.fromfile("path/to/file", "uint8", limit)
我现在需要重塑这个数组:
mat_new=np.zeros([4269, 288, 352, 3], dtype='uint8')
mat_new=np.transpose(np.reshape(mat1,[4269,3,288,352]), [0,2,3,1])
这需要大约35秒对我的4GB内存,i7的第二代系统。 任何方式,我可以让它更快。因为这只是我的计划的开始和更复杂的事情。我从此不需要mat1
!
此外,我只读了一半的文件,因为Python给了我'最大内存达到'的错误。
您不需要先创建一个零数组,您可以删除'np.zeros()'行。从文件中读取数据很慢,请查看您的代码以确定'np.fromfile()'的时间消耗。 – HYRY
大约需要18秒钟才能读取1.25GB的数据!和12-14秒重塑! – change