使用VL格式将字符串列表从Python存储到HDF5数据集

使用VL格式将字符串列表从Python存储到HDF5数据集,python,hdf5,h5py,Python,Hdf5,H5py,我希望下面的代码能够工作,但它没有 import h5py import numpy as np with h5py.File('file.hdf5','w') as hf: dt = h5py.special_dtype(vlen=str) feature_names = np.array(['a', 'b', 'c']) hf.create_dataset('feature names', data=feature_names, dtype=dt) 我收到了错误消

我希望下面的代码能够工作,但它没有

import h5py
import numpy as np

with h5py.File('file.hdf5','w') as hf:
    dt = h5py.special_dtype(vlen=str)
    feature_names = np.array(['a', 'b', 'c'])
    hf.create_dataset('feature names', data=feature_names, dtype=dt)

我收到了错误消息
TypeError:dtype:dtype没有转换路径(“您几乎完成了,缺少的细节是将
dtype
传递到
np.array

import h5py                                                                                                                                                                                                
import numpy as np            

with h5py.File('file.hdf5','w') as hf: 
     dt = h5py.special_dtype(vlen=str) 
     feature_names = np.array(['a', 'b', 'c'], dtype=dt) 
     hf.create_dataset('feature names', data=feature_names)

PS:对我来说这看起来像一个bug-
create\u dataset
忽略给定的
dtype
,不将其应用于给定的
数据

定义“直截了当”。你的循环工作起来就像“直截了当”“我希望有一种Python类型可以用于可变长度字符串的序列/列表/向量,可以直接由
hp5y
使用。
ds[:]=feature\u name
工作吗?或者
data=feature\u name.astype(object)
?@hpaulj
ds[:]=feature\u names
有效,但您的第二个选项无效。如果您想将其转化为答案,我会投票支持。此外,除非有人想出方法将列表传递到
create\u dataset
函数,否则我会接受它。
import h5py                                                                                                                                                                                                
import numpy as np            

with h5py.File('file.hdf5','w') as hf: 
     dt = h5py.special_dtype(vlen=str) 
     feature_names = np.array(['a', 'b', 'c'], dtype=dt) 
     hf.create_dataset('feature names', data=feature_names)