h5py 是否有可能创建一个由字符串列表组成的数据集。我尝试创建一个可变长度的嵌套数据类型,但这会导致我的 python 解释器出现分段错误。
def create_dataset(h5py_file):
data = [['I', 'am', 'a', 'sentecne'], ['another', 'sentence']]
string_dt = h5py.special_dtype(vlen=str)
nested_dt = h5py.special_dtype(vlen=string_dt)
h5py_file.create_dataset("sentences", data=data, dtype = nested_dt)
如果您不打算编辑 hdf5 文件(并且可能使用更长的字符串),您也可以简单地使用:
h5py_file.create_dataset("sentences", data=np.array(data, dtype='S'))
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)