您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

Python:如何在PyTables中存储一个Numpy多维数组?

Python:如何在PyTables中存储一个Numpy多维数组?

可能有一种更简单的方法,但是据我所知,这就是您要做的事情:

import numpy as np
import tables

# Generate some data
x = np.random.random((100,100,100))

# Store "x" in a chunked array...
f = tables.open_file('test.hdf', 'w')
atom = tables.Atom.from_dtype(x.dtype)
ds = f.createCArray(f.root, 'somename', atom, x.shape)
ds[:] = x
f.close()

如果要指定要使用的压缩,请查看tables.Filters。例如

import numpy as np
import tables

# Generate some data
x = np.random.random((100,100,100))

# Store "x" in a chunked array with level 5 BLOSC compression...
f = tables.open_file('test.hdf', 'w')
atom = tables.Atom.from_dtype(x.dtype)
filters = tables.Filters(complib='blosc', complevel=5)
ds = f.createCArray(f.root, 'somename', atom, x.shape, filters=filters)
ds[:] = x
f.close()

可能有很多更简单的方法……pytables很长一段时间以来,我除了表型数据外没有用过其他任何东西。

在pytables 3.0中,f.createCArray重命名f.create_carray。它也可以直接接受数组,而无需指定atom

f.create_carray('/', 'somename', obj=x, filters=filters)
python 2022/1/1 18:31:28 有437人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶