2012-05-10 99 views
1

如何(1)批量选择hdf5文件下的所有数组,然后(2)对这些数组应用计算,最后(3)在另一个hdf5文件中批量创建新数组?如何在Numpy中批量选择和计算数组?

例如:

import numpy 
import tables 

file = openFile('file1',"r") 

array1 = file.root.array1 
array1_cal = (array1 <= 1) 
newfile.createArray('/','array1_cal',array1_cal) 

array2 = file.root.array2 
array2_cal = (array2 <= 1) 
newfile.createArray('/','array2_cal',array2_cal) 

我下单HDF5文件和几个HDF5文件100+阵列,我怎么能批量处理他们?非常感谢。

+0

你的HDF文件的结构是什么?例如,所有的数组都挂在根上?你是否希望在新文件中复制该结构? – dtlussier

回答

2

随着PyTables可以使用walkNodes功能通过递归迭代的节点。这里是一个例子:

# Recursively print all the nodes hanging from '/detector'. 
print "Nodes hanging from group '/detector':" 
for node in h5file.walkNodes('/detector', classname='EArray'): 
    data = node[:] 
    // do some calculation 
    // store new array in second file