def storeFlagsFile(FLAGS_F, file_name, t0, text, ID):
if not FLAGS_F: # this flag doesnt work for mulitple users
f = h5py.File(file_name, "r+")
data_content = np.array([np.round(time.time() - t0, 3), text])
asciiList = np.array([str(n).encode("utf-8", "ignore") for n in data_content]).reshape(1, 2)
dt = h5py.string_dtype(encoding='utf-8')
dset = f[str(ID)].create_dataset('AcqFlags', data=asciiList, compression="gzip", chunks=True, maxshape=(None, 2), dtype=dt)
FLAGS_F = 1
else:
f = h5py.File(file_name, "r+")
data_content = np.array([np.round(time.time() - t0, 3), text])
asciiList = np.array([str(n).encode("utf-8", "ignore") for n in data_content]).reshape(1, 2)
f[str(ID)+'/AcqFlags'].resize((f[str(ID)+'/AcqFlags'].shape[0] + 1), axis = 0)
f[str(ID)+'/AcqFlags'][-1:] = asciiList
我想将这样的数据格式保存为格式(None,2),因为我通过调用storeFlagsFile函数不断更新每行的数据行
['4.412' 'a']
['5.412' 'b']
['6.412' 'c']
['8.226' 'd']
其中t0是数据的第一列,text=第二列,我将其作为每行的输入行提供给storeFlagsFile(FLAGS\F,file\u name,t0,text,ID)。标志F最初为0且ID=“122”
有人能指出我做错了什么吗?谢谢大家!
(我)不清楚为什么在
AcqFlags
数据集中没有两个字段。我能够让您的代码段通过一个小的修改来工作。(我使用的是h5py 2.9.0。在h5py 2.10.0中为可变长度字符串添加了一个新的数据类型。在dt=
声明中注释了该更改。这不是代码中的错误。)请参见下文其他想法/意见:
AcqFlags
数据集。您可以将其简化为测试是否存在,或者使用require_dataset
李>如果您感兴趣,我回答了其他问题,说明如何执行上面的第2和第3项。您可能会发现以下答案之一很有帮助:
相关问题 更多 >
编程相关推荐