1、关于安装:

如果你使用的是Anaconda的话,安装命令如下:

conda install h5py

如果没有,安装命令如下:

pip install h5py

2、核心概念

读取HDF5文件,假如现有一个HDF5文件test.hdf5

>>> import h5py
>>> f = h5py.File("test.hdf5", "r")

第一行导入h5py模块,第二行读取文件为File object。对File object操作就行Python的字典相似;

>>> list(f.keys())
['mydataset']

这样我们可以查看key,就像字典一样。经查看里面有一个数据“mydataset”,我们可以提取该数据;

>>> dset = f["mydataset"]

读取出来的数据更像是Python中的Numpy arrays对象;

>>> dset.shape
(100,)
>>> dset.dtype
dtype('int32')

支持数组的切片;

>>> dset[...] = np.arange(100)
>>> dset[0]
0
>>> dset[10]
10
>>> dset[1:100:10]
array([0, 10, 20, 30, 40, 50, 60, 70, 80, 90])

3、创建一个文件和数据

>>> import h5py
>>> import numpy as np
>>> f = h5py.File("mytestfile.hdf5", "w")
>>> dset = f.create_dataset("mydataset", (100,), dtype='i')

4、组和层级组织

>>> dset.name
u'/mydataset'

The "folders" in this system are called groups, The File object we create is itself a group, in this case the root group ,name /

>>> f.name
u'/'

当然也可以创建子组;

>>> dset2 = h5py.File('mydataset..hdf5', 'a')
>>> grp = f.create_group("subgroup")
>>> dset2 = grp.create_dataset('another_dataset", (50,), dtype='f')
>>> dset2.name
u'/subgroup/another_dataset'

可以直接指定路径创建;

>>> dset3 = f.create_dataset('subgroup2/dataset_three', (10,), dtype='i')
>>> dset3.name
u'/subgroup2/dataset_three'

Python h5py的更多相关文章

  1. Python+H5py实现将SVHN样本库转换为FasterRcnn训练样本

    一.上代码 import os import h5py svhnPath = 'D:\\Project\\AIProject\\SVHNClassifier\\data' def loadSvhn(p ...

  2. [Python]h5py/__init__.py:36:

    个人博客地址:https://www.bearoom.xyz/2019/08/24/python-devolop-env-hdf5-problem/ 安装tensorflow之后,在导入tensorf ...

  3. Python实现单神经元分类图片的训练

    1.加载包和数据 numpy is the fundamental package for scientific computing with Python. h5py is a common pac ...

  4. 课程一(Neural Networks and Deep Learning),第四周(Deep Neural Networks) —— 3.Programming Assignments: Deep Neural Network - Application

    Deep Neural Network - Application Congratulations! Welcome to the fourth programming exercise of the ...

  5. 课程一(Neural Networks and Deep Learning),第二周(Basics of Neural Network programming)—— 4、Logistic Regression with a Neural Network mindset

    Logistic Regression with a Neural Network mindset Welcome to the first (required) programming exerci ...

  6. Linux写配置HDF5的python包h5py

    闲言碎语不讲,直接进入正题.Python在科学计算的应用越来越丰度,而hdf(5)数据的应用也非常广泛.python提供了h5py包供开发者处理数据(http://www.h5py.org/).在wi ...

  7. python使用h5py读取mat文件数据,并保存图像

    1 安装h5py sudo apt-get install libhdf5-dev sudo pip install h5py 假设你已经安装好python和numpy模块 2 读取mat文件数据 i ...

  8. hdf 5文件格式及python中利用h5py模块读写h5文件

    h5文件格式,HDF 的版本 5(HDF 版本 5不与 HDF 版本 4 及早期版本兼容).HDF是什么呢?就是Hierarchical Data Format,可以存储不同类型的图像和数码数据的文件 ...

  9. 杂: PYTHON上数据储存:推荐h5py

    一篇很短的小短文,主要推荐下做科学计算是大量数据的储存问题 最近在做一个CNN的项目,文件夹里有20w张图片要读入并保存到一个data文件(不然每次都读20w文件太麻烦). 折腾了一个下午,发现了一个 ...

随机推荐

  1. jquery中的 parseJSON() 源码分析

    parseJSON: function( data ) { // Attempt to parse using the native JSON parser first if ( window.JSO ...

  2. css 动态线条制作方案

    利用 :before   or    :after  在元素中添加线条样式: 设置样式的过渡效果属性值: 改变width,left,transform等属性值,设置鼠标移入:hover 效果: li: ...

  3. Linux中 ./configure --prefix命令

    源码的安装一般由3个步骤组成:配置(configure).编译(make).安装(make install),具体的安装方法一般作者都会给出文档,这里主要讨论配置(configure).Configu ...

  4. java第四章接口

    接口(interface) 语法:修饰符 interface 接口名 extends 父接口1,父接口2....{ //常量定义   //方法定义} class 类名 extends 父类名 impl ...

  5. poj2828(线段树查找序列第k小的值)

    题目链接:https://vjudge.net/problem/POJ-2828 题意:有n个人,依次给出这n个人进入队列时前面有多少人p[i],和它的权值v[i],求最终队列的权值序列. 思路:基本 ...

  6. systemverilog soft constraint

    1.class my_item; rand bit constrainted_random; rand bit usually_one; endclass class my_generator; my ...

  7. 微信小程序日历面板插件

    创建日历面板组件,在components目录下创建calendar文件夹 1.calendar.js // components/calendar/calendar.js var util = req ...

  8. 牛客小白月赛13 小A的最短路(lca+RMQ)

    链接:https://ac.nowcoder.com/acm/contest/549/F来源:牛客网 题目描述 小A这次来到一个景区去旅游,景区里面有N个景点,景点之间有N-1条路径.小A从当前的一个 ...

  9. R语言如何读取.csv文件

    以下是我关于如何在R语言中读取.csv文件及一些需要注意的细节的总结,希望能帮助到大家~

  10. Spring 文件上传MultipartFile 执行流程分析

    在了解Spring 文件上传执行流程之前,我们必须知道两点: 1.Spring 文件上传是基于common-fileUpload 组件的,所以,文件上传必须引入此包 2.Spring 文件上传需要在X ...