2012-05-10 50 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