gpt4 book ai didi

python - 用pytables压缩数组

转载 作者:太空狗 更新时间:2023-10-30 00:45:16 26 4
gpt4 key购买 nike

我正在尝试像这样压缩我的数组

import numpy as np
import tables
from contextlib import closing

FILTERS = tables.Filters(complib='zlib', complevel=5)

data = np.zeros(10**7)

with closing(tables.open_file('compressed', mode='w', filters=FILTERS)) as hdf:
hdf.create_array('/', 'array', obj=data)

with closing(tables.open_file('uncompressed', mode='w')) as hdf:
hdf.create_array('/', 'array', obj=data)

但它根本不起作用

-rw-rw-r-- 1 user user 80002360 2013-11-21 15:27 compressed
-rw-rw-r-- 1 user user 80002304 2013-11-21 15:28 uncompressed

我是不是做错了什么?

最佳答案

数组本身不能被压缩。压缩需要分块,因此您必须改用分块数组 (CArrays) 或可扩展数组 (EArray)。这可能是 1 个字符的更改,因为您只想调用 create_carray() 方法而不是 create_array() 方法。

import numpy as np
import tables
from contextlib import closing

FILTERS = tables.Filters(complib='zlib', complevel=5)

data = np.zeros(10**7)

with closing(tables.open_file('compressed', mode='w', filters=FILTERS)) as hdf:
hdf.create_carray('/', 'array', obj=data)

with closing(tables.open_file('uncompressed', mode='w')) as hdf:
hdf.create_array('/', 'array', obj=data)

关于python - 用pytables压缩数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20118560/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com