使用H5PY删除HDF5数据集 [英] Deleting hdf5 dataset using h5py

查看:200
本文介绍了使用H5PY删除HDF5数据集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以从hdf5文件中删除数据集,最好使用h5py吗?或者,是否有可能在保留其他数据集完整的同时覆盖一个数据集?



据我所知,h5py可以以5种模式读取/写入hdf5文件

  f = h5py.File( filename.hdf5,'mode')

其中模式可以是 r 以便读取, r + a 用于读写,但如果不存在则创建一个新文件, w 用于读写写入/覆盖,以及 w- w 相同,但如果文件已存在则失败。我已经尝试了所有方法,但似乎都没有效果。



任何建议都值得赞赏。

解决方案

是的,可以完成。

 ,其中h5py.File(input, a)as f:
del f [datasetname]

您将需要以可写模式打开文件,例如追加(如上所述)或写入。 / p>

正如@ seppo-enarvi在评论中指出的,以前建议的用途 f .__ delitem __(datasetname) 功能是实现 del 操作符,以便可以使用 del f [datasetname]


Is there any way to remove a dataset from an hdf5 file, preferably using h5py? Or alternatively, is it possible to overwrite a dataset while keeping the other datasets intact?

To my understanding, h5py can read/write hdf5 files in 5 modes

f = h5py.File("filename.hdf5",'mode')

where mode can be rfor read, r+ for read-write, a for read-write but creates a new file if it doesn't exist, w for write/overwrite, and w- which is same as w but fails if file already exists. I have tried all but none seem to work.

Any suggestions are much appreciated.

解决方案

Yes, this can be done.

with h5py.File(input,  "a") as f:
    del f[datasetname]

You will need to have the file open in a writeable mode, for example append (as above) or write.

As noted by @seppo-enarvi in the comments the purpose of the previously recommended f.__delitem__(datasetname) function is to implement the del operator, so that one can delete a dataset using del f[datasetname]

这篇关于使用H5PY删除HDF5数据集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆