【发布时间】:2020-03-10 04:47:47
【问题描述】:
我检查了不同的解决方案,但不明白如何将它们应用于多维数组。准确地说,我的代码生成的数组比它应该的要大,如下图所示:
import h5py
import pandas as pd
import numpy as np
data = [[1583663558450195, -7.063664436340332, -6.2776079177856445, -4.206898212432861, -4.206898212432861], [1583663558450195, -7.063664436340332, -6.2776079177856445, -4.206898212432861, -4.206898212432861], [1583663558450195, -7.063664436340332, -6.2776079177856445, -4.206898212432861, -4.206898212432861], [1583663558450195, -7.063664436340332, -6.2776079177856445, -4.206898212432861, -4.206898212432861], [1583663558450195, -7.063664436340332, -6.2776079177856445, -4.206898212432861, -4.206898212432861], [1583663558450195, -7.063664436340332, -6.2776079177856445, -4.206898212432861, -4.206898212432861], [1583663558450195, -7.063664436340332, -6.2776079177856445, -4.206898212432861, -4.206898212432861], [1583663558450195, -7.063664436340332, -6.2776079177856445, -4.206898212432861, -4.206898212432861], [1583663558450195, -7.063664436340332, -6.2776079177856445, -4.206898212432861, -4.206898212432861], [1583663558450195, -7.063664436340332, -6.2776079177856445, -4.206898212432861, -4.206898212432861]]
df = pd.DataFrame(data)
hf = h5py.File('dtype.h5', 'w')
dataTypes = np.dtype([('ts', 'u8'), ('x', 'f4'), ('y', 'f4'), ('z', 'f4'), ('temp', 'f4')])
ds = hf.create_dataset('Acceleration', data=df.astype(dataTypes))
我想做成这样,列分别是 uint64, 4x float32:
ts x y z temp
0 1583663558450195 -7.063664 -6.277608 -4.206898 -4.206898
1 1583663558450195 -7.063664 -6.277608 -4.206898 -4.206898
2 1583663558450195 -7.063664 -6.277608 -4.206898 -4.206898
3 1583663558450195 -7.063664 -6.277608 -4.206898 -4.206898
4 1583663558450195 -7.063664 -6.277608 -4.206898 -4.206898
5 1583663558450195 -7.063664 -6.277608 -4.206898 -4.206898
6 1583663558450195 -7.063664 -6.277608 -4.206898 -4.206898
7 1583663558450195 -7.063664 -6.277608 -4.206898 -4.206898
8 1583663558450195 -7.063664 -6.277608 -4.206898 -4.206898
9 1583663558450195 -7.063664 -6.277608 -4.206898 -4.206898
【问题讨论】: