group python 读hdf5_在python中正确设置和读取hdf5文件中的dimscale

在使用Python的h5py库尝试为HDF5文件的维度附加尺度时遇到问题。代码创建了一个数据集并设置了维度标签,但在将尺度附加到维度后,尝试打印属性时发生错误。错误提示为'TypeError: No NumPy equivalent for TypeVlenID exists'。寻求解决方案。
摘要由CSDN通过智能技术生成

我试图用python将维度比例附加到要存储在hdf5文件中的数据集,但是在设置属性后尝试打印这些属性时出现错误。相关代码片段如下:import h5py

import numpy as np

# create data and x-axis

my_data = np.random.randint(10, size=(100, 200))

x_axis = np.linspace(0, 1, 100)

h5f = h5.File('my_file.h5','w')

h5f.create_dataset( 'data_1', data=my_data )

h5f['data_1'].dims[0].label = 'm'

h5f['data_1'].dims.create_scale( h5f['x_axis'], 'x' )

# the following line is creating the problems

h5f['data_1'].dims[0].attach_scale( h5f['x_axis'] )

# this is where the crash happens but only if the above line is included

for ii in h5f['data_1'].attrs.items():

print ii

h5f.close()

命令print(h5.version.info)打印以下输出:

^{pr2}$

错误消息如下:Traceback (most recent call last):

File "HDF_write_dimScales.py", line 16

for ii in h5f['data_1'].attrs.items():

File "/usr/lib/python2.7/dist-packages/h5py/_hl/base.py", line 347, in items

return [(x, self.get(x)) for x in self]

File "/usr/lib/python2.7/dist-packages/h5py/_hl/base.py", line 310, in get

return self[name]

File "/usr/lib/python2.7/dist-packages/h5py/_hl/attrs.py", line 55, in __getitem__

rtdt = readtime_dtype(attr.dtype, [])

File "h5a.pyx", line 318, in h5py.h5a.AttrID.dtype.__get__ (h5py/h5a.c:4285)

File "h5t.pyx", line 337, in h5py.h5t.TypeID.py_dtype (h5py/h5t.c:3892)

TypeError: No NumPy equivalent for TypeVlenID exists

任何想法或暗示都是值得赞赏的。在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值