【发布时间】:2012-05-09 14:35:17
【问题描述】:
如何在 Numpy 中自动处理升序的文件名和数组名:
我有一系列名为:
的 HDF5 文件20120101.hdf5, 20120102.hdf5, 20120103.hdf5, ..., 20120130.hdf5, 20120131.hdf5
每个 hdf5 文件包含几个数组命名:
array1, array2, array3, ..., array24
我想分别修改每个数组,然后创建相应的新 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
【问题讨论】:
-
问题到底是什么?
-
如何自动完成?而不是手动更改名称?
-
你的代码写得不对:如果你写
import tables,那么你必须把这个模块的所有函数写成tables.function。如果你写file = openFile(...)和new = creatArray(...)它是行不通的!要使用您编写的代码,您必须将模块称为from tables import openFile, creatArray或from tables import *
标签: python iteration filenames hdf5