2017-08-09 5 views
2

numpy型のPython辞書をH5ファイルにシリアライズしています。h5pyが受け入れるnumpy dtypesは何ですか?

一般的に、コードは、私がXXXXXXに入れるに何に苦しんでいます

for key, value in dict.items(): 
    if isinstance(value, str): 
     f.attrs[key] = value.encode('utf-8') 
    elif isinstance(value, XXXXXX): 
     param_dset = f.create_dataset(key, value.shape, dtype=value.dtype) 
     if not value.shape: 
      # scalar 
      param_dset[()] = value 
     else: 
      param_dset[:] = value 
    elif isinstance(value, dict): 
     save_dict_to_hdf5_group(f.create_group(key), value) 
    else: 
     raise ValueError('Cannot save type "%s" to HDF5' % type(value)) 

です。具体的には、numpy型を置くことはできますか、またはH5は特定の型だけを格納しますか?

たとえば、​​が選択肢ですが、float32が不足します。 (np.ndarray, np.generic)は別の選択肢ですが、H5pyはすべての汎用numpy型を受け入れますか?

完全にサポートされているタイプ:h5pyドキュメントから

答えて

2

Type  Precisions         Notes 
Integer 1, 2, 4 or 8 byte, BE/LE, signed/unsigned  
Float  2, 4, 8, 12, 16 byte, BE/LE 
Complex 8 or 16 byte, BE/LE       Stored as HDF5 struct 
Compound Arbitrary names and offsets 
Strings (fixed-length) Any length 
Strings (variable-length) Any length, ASCII or Unicode  
Opaque  (kind ‘V’) Any length 
Boolean  NumPy 1-byte bool        Stored as HDF5 enum 
Array  Any supported type 
Enumeration Any NumPy integer type      Read/write as integers 
References Region and object  
Variable length array Any supported type    See Special Types 

サポートされていないタイプ:

Type     
HDF5 “time” type  
NumPy “U” strings 
NumPy generic “O” 
関連する問題