问题描述
如何可以把一个numpy的多维数组在HDF5文件中使用PyTables?
How can I put a numpy multidimensional array in a HDF5 file using PyTables?
这是我可以告诉我不能把一个数组字段和pytables表。
From what I can tell I can't put an array field in a pytables table.
我也需要存储有关这个数组的一些信息,并能够做就可以了数学计算。
I also need to store some info about this array and be able to do mathematical computations on it.
有什么建议?
推荐答案
有可能是一个更简单的方法,但这是你如何去这样做,据我所知:
There may be a simpler way, but this is how you'd go about doing it, as far as I know:
import numpy as np
import tables
# Generate some data
x = np.random.random((100,100,100))
# Store "x" in a chunked array...
f = tables.openFile('test.hdf', 'w')
atom = tables.Atom.from_dtype(x.dtype)
ds = f.createCArray(f.root, 'somename', atom, x.shape)
ds[:] = x
f.close()
如果您要指定COM pression使用,看看 tables.Filters
。例如。
If you want to specify the compression to use, have a look at tables.Filters
. E.g.
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.openFile('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
在很长一段时间比表状数据的任何其他。
There's probably a simpler way for a lot of this... I haven't used pytables
for anything other than table-like data in a long while.
这篇关于蟒蛇:如何存储在一个PyTables numpy的多维数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!