获取 python numpy ndarray 的列名
假设我有一个名为 data.txt
的数据文件,如下所示:
TIME FX FY FZ
0 10 5 6
1 2 4 7
2 5 2 6
...
在 Python 中运行:
import numpy as np
myData = np.genfromtxt("data.txt", names=True)
>>> print myData["TIME"]
[0, 1, 2]
数据文件顶部的名称会有所不同,所以我想做的是找出数据文件中我的数组的名称是。我想要这样的东西:
>>> print myData.names
[TIME, F0, F1, F2]
我想过只读取数据文件并获取第一行并将其解析为单独的操作,但这似乎不是很有效或优雅。
Let's say I have a data file called data.txt
that looks like:
TIME FX FY FZ
0 10 5 6
1 2 4 7
2 5 2 6
...
In Python run:
import numpy as np
myData = np.genfromtxt("data.txt", names=True)
>>> print myData["TIME"]
[0, 1, 2]
The names at the top of my data file will vary, so what I would like to do is find out what the names of my arrays in the data file are. I would like something like:
>>> print myData.names
[TIME, F0, F1, F2]
I thought about just to read in the data file and get the first line and parse it as a separate operation, but that doesn't seem very efficient or elegant.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试:
这将返回字段名称的元组。
Try:
This will return a tuple of the field names.