h5py 是否将整个文件读入内存?

Does h5py read the whole file into memory?

h5py是否将整个文件读入内存?

如果是这样,如果我有一个非常非常大的文件怎么办?

如果不是,每次要单条数据时,从硬盘上取数据会不会很慢?我怎样才能让它更快?

Does h5py read the whole file into the memory?

不,不是。特别是,切片 (dataset[50:100]) 允许您将数据集的一部分加载到内存中。有关详细信息,请参阅 h5py docs.

If not, will it be quite slow if I take data from hard disk every time I want a single data?

总的来说,hdf5 非常快。但是从内存中读取显然比从磁盘中读取要快。将多少数据集读入内存由您决定(dataset[:] 加载整个数据集)。

How can I make it faster?

如果你想优化性能,你应该阅读 sections about chunking and compression. There's also a book 详细解释了这些事情(免责声明:我不是作者)。