【问题标题】:compressing array with pytables用 pytables 压缩数组
【发布时间】:2013-12-05 18:44:24
【问题描述】:

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

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

我在这里做错了吗?

【问题讨论】:

    标签: python hdf5 pytables


    【解决方案1】:

    数组本身不能被压缩。压缩需要分块,因此您必须改用分块数组 (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)
    

    【讨论】:

    • 感谢您的回答。我没有注意文档中的这一刻。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-02-06
    • 2016-12-26
    • 1970-01-01
    • 1970-01-01
    • 2011-12-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多