栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

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

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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

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

import numpy as npimport tables# Generate some datax = 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[:] = xf.close()

如果要指定要使用的压缩,请查看

tables.Filters
。例如

import numpy as npimport tables# Generate some datax = 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[:] = xf.close()

可能有很多更简单的方法……

pytables
很长一段时间以来,我除了表型数据外没有用过其他任何东西。

注意: 在pytables
3.0中,

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

f.create_carray('/', 'somename', obj=x, filters=filters)


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/410705.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号