如何在Numpy中自动处理升序文件名和数组名:
我有一系列名为:
20120101.hdf5, 20120102.hdf5, 20120103.hdf5, ..., 20120130.hdf5, 20120131.hdf5
每个hdf5文件都包含几个数组,命名为:
^{pr2}$我想分别修改每个数组,然后创建相应的新hdf5文件。例如,使用20120101.hdf5
:
import numpy
import tables
file = openFile("20120101.hdf5","r")
b1 = file.root.array1
c1 = (b1<=1)
new20120101_array1 = creatArray('/','1',c1)
c2 = ((b1<=2) and (b>1))
new20120101_array1 = creatArray('/','2',c2)
.
.
.
c20 = ((b1<=20) and (b>19))
new20120101_array1 = creatArray('/','20',c20)
对阵列2-24重复此操作。因此,我希望:
new20120101.hdf5 ---- new20120101_array1 ---- 1
2
...
20
---- new20120101_array2 ---- 1
...
20
...
---- new20120101_array24 --- 1
...
20
new20120102.hdf5
....
new20120131.hdf5
如果一个目录中有多个文件,可以使用
os.listdir
函数,该函数返回一个包含目录项名称的列表。在示例:
我想你问题的另一部分已经在你的other question中得到了回答(你可以使用
walkNodes
函数)。在相关问题 更多 >
编程相关推荐