我需要在Python或Matlab中进行涉及60000X70000矩阵的乘法运算。 我有16GB的RAM,并且能够轻松加载矩阵的每一行(这是我所需的)。 我能够在Python中创建整个矩阵,但无法在Matlab中完成。 是否有任何方法可以使用h5py或scipy将数组保存为.v7.3格式的.mat文件,以便我可以单独加载每一行?
我需要在Python或Matlab中进行涉及60000X70000矩阵的乘法运算。 我有16GB的RAM,并且能够轻松加载矩阵的每一行(这是我所需的)。 我能够在Python中创建整个矩阵,但无法在Matlab中完成。 是否有任何方法可以使用h5py或scipy将数组保存为.v7.3格式的.mat文件,以便我可以单独加载每一行?
import h5py
import hdf5storage
import numpy as np
matfiledata = {} # make a dictionary to store the MAT data in
matfiledata[u'variable1'] = np.zeros(100) # *** u prefix for variable name = unicode format, no issues thru Python 3.5; advise keeping u prefix indicator format based on feedback despite docs ***
matfiledata[u'variable2'] = np.ones(300)
hdf5storage.write(matfiledata, '.', 'example.mat', matlab_compatible=True)
matfiledata[u'chunk1'] matfiledata[u'chunk2'] matfiledata[u'chunk3']
等等。
然后在 MATLAB 中,如果您将每个块保存为一个变量,则可以:
load(filename,'chunk1')
do stuff...
clear chunk1
load(filename,'chunk2')
do stuff...
clear chunk2
hdf5storage.savemat函数有一个参数,可以让文件在将来正确地读入Python中,因此值得一试。它遵循scipy.io.loadmat格式... 如果从MATLAB保存数据以便轻松导入到Python中,您可以像这样做:
MATLAB
save('example.mat','-v7.3')
Python
matdata = hdf5storage.loadmat('example.mat')
hdf5storage.write
命令时,出现了内存错误,有没有解决方法? - SH_V95