在我的例子中,输出文件 (earray.h5) 的大小很大。有没有办法附加数据,使输出文件不那么大?例如,在我的例子中(见下面的链接)一个 13GB 的输入文件(dset_1:2.1E8 x 4 和 dset_2:2.1E8 x 4)给出了一个只有一列(2.5E10 x 1)的 197 GB 输出文件。所有元素都是 float64。
我想减小输出文件的大小,这样脚本的执行速度就不会受到影响,并且输出文件的读取也可以高效地供以后使用。沿着列而不只是行保存数据有帮助吗?对此有什么建议吗?下面给出的是一个 MWE。
# no. of chunks from dset-1 and dset-2 in inp.h5
loop_1 = 40
loop_2 = 20
# save to disk after these many rows
app_len = 10**6
# **********************************************
# Grabbing input.h5 file
# **********************************************
filename = 'inp.h5'
f2 = h5py.File(filename, 'r')
chunks1 = f2['dset_1']
chunks2 = f2['dset_2']
shape1, shape2 = chunks1.shape[0], chunks2.shape[0]
f1 = tables.open_file("table.h5", "w")
a = f1.create_earray(f1.root, "dataset_1", atom=tables.Float64Atom(), shape=(0, 4))
size1 = shape1//loop_1
size2 = shape2//loop_2
# ***************************************************
# Grabbing chunks to process and append data
# ***************************************************
for c in range(loop_1):
h = c*size1
# grab chunks from dset_1 of inp.h5
chunk1 = chunks1[h:(h + size1)]
for d in range(loop_2):
g = d*size2
chunk2 = chunks2[g:(g + size2)] # grab chunks from dset_2 of inp.h5
r1 = chunk1.shape[0]
r2 = chunk2.shape[0]
left, right = 0, 0
for j in range(r1): # grab col.2 values from dataset-1
e1 = chunk1[j, 1]
#...Algaebraic operations here to output a row containing 4 float64
#...append to a (earray) when no. of rows reach a million
del chunk2
del chunk1
f2.close()
HUH函数
相关分类