def fill_hdf5_with_sparse_by_chunk(mym1,mym2,fname,chunksize):
start1=0
end1=0
n=mym1.shape[0]
f=h5py.File(fname,'w')
m1hdf5=f.create_dataset('m1',shape=(n,n),dtype='float')
m2hdf5=f.create_dataset('m2',shape=(n,n),dtype='float')
while end1<n:
end1=np.min([n,(start1+chunksize)])
print 'start1: '+str(start1)
if (end1-start1)==1:
m1hdf5[start1,:]=mym1[start1,:].toarray()
m2hdf5[start1,:]=mym2[start1,:].toarray()
else:
m1hdf5[start1:end1,:]=mym1[start1:end1,:].toarray()
m2hdf5[start1:end1,:]=mym2[start1:end1,:].toarray()
start1=end1
print 'sum of 1'
print m1hdf5[:,:].sum()
print m2hdf5[:,:].sum()
f.close()
评论列表
文章目录