python - 用pytables压缩数组

标签 python hdf5 pytables

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

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/

相关文章:

python-3.x - 如何在 Windows 10 上安装 HDF5 版本 1.10.5

python - 如何在 Debian Linux 系统上以非 root 身份安装 h5py (+numpy+libhdf5+...)

python - 如何为 Pytables EArray 创建定义原子

python - 在小块中创建非常大的 NUMPY 数组(PyTables 与 numpy.memmap)

python - 从 HDF5 获取表索引的最有效方法

Python argparse - 向多个子解析器添加参数

python - 如何逐行读取文件中的文件?

Python - 如何合并一个 df 中的列值以匹配另一个 df 中的行?

python - Tensorflow 的 Between-graph replication 是数据并行的一个例子吗?

python - HDF5 文件内的损坏节点