cpickle安装_Py之h5py:Python库之h5py库的简介、安装、使用方法详细攻略
Py之h5py:Python庫之h5py庫的簡介、安裝、使用方法詳細攻略
目錄
h5py的簡介
Websites
Installation
Reporting bugs
h5py的安裝
h5py的使用方法
1、寫入數(shù)據(jù)
2、讀取數(shù)據(jù)
h5py的簡介
使用h5py庫讀寫超過內存的大數(shù)據(jù) 。在簡單數(shù)據(jù)的讀操作中,我們通常一次性把數(shù)據(jù)全部讀入到內存中。讀寫超過內存的大數(shù)據(jù)時,有別于簡單數(shù)據(jù)的讀寫操作,受限于內存大小,通常需要指定位置、指定區(qū)域讀寫操作,避免無關數(shù)據(jù)的讀寫。 h5py庫剛好可以實現(xiàn)這一功能。
h5py的優(yōu)勢:速度快、壓縮效率高,總之,numpy.savez和cPickle存儲work或不work的都可以試一試h5py!h5py文件是存放兩類對象的容器,數(shù)據(jù)集(dataset)和組(group),dataset類似數(shù)組類的數(shù)據(jù)集合,和numpy的數(shù)組差不多。group是像文件夾一樣的容器,它好比python中的字典,有鍵(key)和值(value)。group中可以存放dataset或者其他的group。”鍵”就是組成員的名稱,”值”就是組成員對象本身(組或者數(shù)據(jù)集),下面來看下如何創(chuàng)建組和數(shù)據(jù)集。
相關文章:HDF5 for Python
h5py is a thin, pythonic wrapper around the HDF5, which runs on Python 3 (3.6+).
Websites
- Main website: https://www.h5py.org
- Source code: https://github.com/h5py/h5py
- Mailing list: https://groups.google.com/d/forum/h5py
Installation
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.
Reporting bugs
Open a bug at https://github.com/h5py/h5py/issues. For general questions, ask on the list (https://groups.google.com/d/forum/h5py).
h5py的安裝
pip install h5py
?
安裝成功!哈哈,繼續(xù)學習去啦!
h5py的使用方法
后期更新……
1、寫入數(shù)據(jù)
import h5py"""create_dataset : 新建 datasetcreate_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)2、讀取數(shù)據(jù)
"""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')參考文章
h5py 必知--String存儲
總結
以上是生活随笔為你收集整理的cpickle安装_Py之h5py:Python库之h5py库的简介、安装、使用方法详细攻略的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 机器学习中val_小波变换(七):小波变
- 下一篇: python决策树分类 导入数据集_py