Py之h5py:Python庫之h5py庫的簡介、安裝、使用方法詳細攻略html
目錄python
h5py的簡介git
Websitesgithub
Installationweb
h5py的安裝app
h5py的使用方法ide
一、寫入數據學習
二、讀取數據大數據
使用h5py庫讀寫超過內存的大數據 。在簡單數據的讀操做中,咱們一般一次性把數據所有讀入到內存中。讀寫超過內存的大數據時,有別於簡單數據的讀寫操做,受限於內存大小,一般須要指定位置、指定區域讀寫操做,避免無關數據的讀寫。 h5py庫恰好能夠實現這一功能。
h5py的優點:速度快、壓縮效率高,總之,numpy.savez和cPickle存儲work或不work的均可以試一試h5py!h5py文件是存放兩類對象的容器,數據集(dataset)和組(group),dataset相似數組類的數據集合,和numpy的數組差很少。group是像文件夾同樣的容器,它比如python中的字典,有鍵(key)和值(value)。group中能夠存放dataset或者其餘的group。」鍵」就是組成員的名稱,」值」就是組成員對象自己(組或者數據集),下面來看下如何建立組和數據集。
相關文章:HDF5 for Python
h5py is a thin, pythonic wrapper around the HDF5, which runs on Python 3 (3.6+).
Pre-build h5py can either be installed via your Python Distribution (e.g. Continuum Anaconda, Enthought Canopy) or from PyPI via pip. h5py is also distributed in many Linux Distributions (e.g. Ubuntu, Fedora), and in the MacOS package managers Homebrew, Macports, or Fink.
More detailed installation instructions, including how to install h5py with MPI support, can be found at: https://docs.h5py.org/en/latest/build.html.
Open a bug at https://github.com/h5py/h5py/issues. For general questions, ask on the list (https://groups.google.com/d/forum/h5py).
pip install h5py
安裝成功!哈哈,繼續學習去啦!
後期更新……
import h5py """ create_dataset : 新建 dataset create_group : 新建 group """ x = np.arange(100) with h5py.File('test.h5','w') as f: f.create_dataset('test_numpy',data=x) subgroup = f.create_group('subgroup') subgroup.create_dataset('test_numpy',data=x) subsub = subgroup.create_group('subsub') subsub.create_dataset('test_numpy',data=x)
""" keys() : 獲取本文件夾下全部的文件及文件夾的名字 f['key_name'] : 獲取對應的對象 """ def read_data(filename): with h5py.File(filename,'r') as f: def print_name(name): print(name) f.visit(print_name) print('---------------------------------------') subgroup = f['subgroup'] print(subgroup.keys()) print('---------------------------------------') dset = f['test_numpy'] print(dset) print(dset.name) print(dset.shape) print(dset.dtype) print(dset[:]) print('---------------------------------------') read_data('test.h5')