h5pyを使用しています。HDF5 ファイル内に、文字列 (column1) と region_reference (column2) の複合データセットが必要です。このために、文字列と参照のnumpy dtypeを定義しようとしています。
しかし、これ以前でも、hdf5 地域参照の numpy dtype 配列を定義できていません。
##map_h5py.py
import h5py
import numpy as np
h = h5py.File('testing_mapping.h5', 'a')
cell_names = ['cell0', 'cell1', 'cell2', 'cell3']
dummy_data = np.random.rand(4,20)
##create random data
dset = h.create_dataset('/data/Vm', data=dummy_data, dtype='float32')
#declare a data type
sp_type = np.dtype([('ref',h5py.special_dtype(ref=h5py.RegionReference))])
##this works - 1
refs_list = []
for ii in range(dset.shape[0]):
refs_list.append(dset.regionref[ii])
h.create_dataset('/map/Vm_list', data=refs_list, dtype=h5py.special_dtype(ref=h5py.RegionReference))
##this doesn't - 2
ref_dset = h.create_dataset('/map/Vm_pre', shape=(dset.shape[0],), dtype=sp_type)
for ii in range(dset.shape[0]):
ref_dset[ii] = dset.regionref[ii]
# #this doesn't - 3
ref_numpy = np.zeros(dset.shape[0], dtype=sp_type)
for ii in range(dset.shape[0]):
ref_numpy[ii] = dset.regionref[ii]
h.create_dataset('/map/Vm_post', data=ref_numpy, dtype=sp_type)
h.close()
2と3の場合のエラーは以下、
ref_numpy[ii] = dset.regionref[ii]
ValueError: Setting void-array with object members using buffer.