原因

h5py 的String类型只接受ASCII的数据,如果你是Python3或者Python使用utf-8的编码就会报错。

import h5py
f = h5py.File('test.hdf', 'w')
f.attrs.create('test', '1234134')

>>> h5py\h5t.pyx in h5py.h5t.py_create()
>>> TypeError: No conversion path for dtype: dtype('<U7')

解决方法

需要使用h5py的special_dtype函数,str对应着Python3的字符串类型。

import h5py
dtype = h5py.special_dtype(vlen=str)
f = h5py.File('test.hdf', 'w')
f.attrs.create('test', '1234134', dtype=dtype)

 

Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐