2016-06-17 7 views
3

h5pyで文字列のリストで構成されるデータセットを作成する可能性はありますか?私は可変長のネストされたデータ型を作成しようとしましたが、これは私のPythonインタプリタでセグメント化の失敗に終わりました。H5pyストアの文字列リスト

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) 

答えて

2

このpostで提案されているようにあなたがむしろリストのリストよりも、DTYPE =オブジェクトのnumpyの配列としてデータを定義する場合は、必要な機能を得ることができる必要があります。

def create_dataset(h5py_file): 
    data = np.array([['I', 'am', 'a', 'sentence'], ['another', 'sentence']], dtype=object) 
    string_dt = h5py.special_dtype(vlen=str) 
    h5py_file.create_dataset("sentences", data=data, dtype=string_dt) 
0

あなたはHDF5ファイルを編集(および潜在的に長い文字列を使用)する予定がない場合は、あなたも簡単に使用することができます。

h5py_file.create_dataset("sentences", data=np.array(data, dtype='S')) 
関連する問題