<p><strong>在磁盘上高效地写入结果</strong></p>
<p>起初,一些人会考虑结果数据的大小。在</p>
<p><strong>结果数据的大小</strong></p>
<pre><code>size_in_GB = A.shape[0]**2*A.shape[1]*B.shape[0]*(size_of_datatype)/1e9
</code></pre>
<p>在你的问题中,你提到了A.shape=(10000,50),B=(40,50)。使用float64,您的结果大约是1600gb。如果您有足够的磁盘空间,这可以毫无问题地完成,但是您必须考虑下一步不能对数据做什么。也许这只是一个中间的结果,处理块中的数据是可能的。在</p>
<p>如果不是这样的话,这里有一个如何有效地处理1600GB数据的例子(RAM使用量大约为200MB)。根据实际数据,troughput应该在200MB/s左右。在</p>
<p>计算结果的代码来自@PaulPanzer。在</p>
^{pr2}$
<p><strong>读取数据</strong></p>
<pre><code>File_Name_HDF5='Test.h5'
f = h5c.File(File_Name_HDF5, 'r',chunk_cache_mem_size=1024**2*300)
dset=f['Data']
chunks_size=500
for i in range(0,dset.shape[0],chunks_size):
#Iterate over the first column
data=dset[i:i+chunks_size,:] #avoid excessive calls to the hdf5 library
#Do something with the data
f.close()
f = h5c.File(File_Name_HDF5, 'r',chunk_cache_mem_size=1024**2*300)
dset=f['Data']
for i in range(dset.shape[1]):
# Iterate over the second dimension
# fancy indexing e.g.[:,i] will be much slower
# use np.expand_dims or in this case np.squeeze after the read operation from the dset
# if you wan't to have the same result than [:,i] (1 dim array)
data=dset[:,i:i+1]
#Do something with the data
f.close()
</code></pre>
<p>在这个测试示例中,我获得了大约550m/s的写入吞吐量,大约(500 M/s的第一个dim,1000M/s的第二个dim)的读吞吐量和50的压缩比。numpymemmap只会提供可接受的速度,如果你沿着变化最快的方向(在最后一个维度的C中)读写数据,这里使用HDF5使用的分块数据格式,这根本不是问题。使用numpymemmap也不可能进行压缩,这会导致更大的文件大小和较慢的速度。在</p>
<p>请注意,压缩过滤器和块形状必须根据您的需要进行设置。这取决于如何避免事后读取数据和实际数据。在</p>
<p>如果你做了完全错误的事情,与正确的方法相比,执行速度可能会慢10-100倍(例如,可以为第一个或第二个阅读示例优化chunkshape)。在</p>