简体   繁体   English

自动解析numpy recarray

[英]automatically resolve numpy recarray

Hi I have some binary Files created in IDL (Interactive Data Language) which can be read through scipy using 嗨,我有一些用IDL(交互式数据语言)创建的二进制文件,可以使用scipy读取

scipy.io.readsav

In particular I used it as follow 特别是我使用它如下

data = scipy.io.readsav("input.sav", python_dict=True)

so that the output is a standard python dictionary. 因此输出是标准的python字典。 In particular the output I can access the numpy.recarray which is stored in the dictionary 特别是输出,我可以访问存储在字典中的numpy.recarray

du = data.keys()
duV = data[du[0]]

so duV now is a recarray. 所以duV现在是一个重新排列。 I don't know a priori the variables and the names which are stored in the recarray. 我不知道先验变量和存储在recarray中的名称。 I can access the names of the variables as 我可以访问变量的名称为

names = duV.dtype.names

Now suppose that names is equal to 现在假设名称等于

('V', 'T', 'THETA', 'ERR')

I would like to find an automatically procedure to read all the variables with the corresponding names, ie something which automatically do as 我想找到一个自动过程,以读取具有相应名称的所有变量,即自动执行的操作

v = duV.field('V')
t = duV.field('T')

ect. 等等。 ect. 等等。 So I would like to create variables which are named as the names of the recarray 所以我想创建被命名为recarray名称的变量

If you want to put all the fields in to global variables, you can do: 如果要将所有字段都放入全局变量中,则可以执行以下操作:

for name in duV.dtype.names:
    globals()[name.lower()] = duV.field(name)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM