2016-06-17 4 views
3

h5py에서 문자열 목록으로 구성된 데이터 집합을 만들 가능성이 있습니까? 가변 길이의 중첩 데이터 유형을 만들려고했지만 파이썬 인터프리터에서 세그먼트 화 오류가 발생합니다.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와 배열로 데이터를 정의하면 당신이 원하는 기능을 얻을 수 있어야합니다. 당신이 (긴 문자열을 잠재적으로 사용)을 HDF5 파일을 편집하지 않으려면

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

, 당신은 또한 간단하게 사용할 수 있습니다

h5py_file.create_dataset("sentences", data=np.array(data, dtype='S'))