我正在尝试像这样压缩我的数组
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/