首页 > 解决方案 > 读取h5数据集python的一部分

问题描述

我正在从 .h5 文件中读取大量数据(每个数据集 200,000 个点),我目前不需要所有这些数据,所以我一直在做的是读取数据,然后截断它。

有没有办法只读取 h5 数据集的前 X 项?

标签: pythonpython-3.xlarge-filesh5py

解决方案


Use this...

import numpy as np
import h5py

filename = 'file.hdf5'
f = h5py.File(filename, 'r')

key = list(f.keys())[0]

data = list(f[key][1])

Indexing may vary for key and f[key], where [0] is an arbitrary dataset of file.hdf5 and [1] is just an arbitrary column I grabbed.


推荐阅读