我试图读取以下文件,我试图使用numpy加载数据:
#Frame HIE_21@O-PHE_32@N-H THR_20@O-PHE_32@N-H HIE_21@ND1-PHE_32@N-H
1 0 0 0
2 1 0 0
3 0 0 0
4 0 0 0
5 0 0 0
如果我从第一行的第一个值开始读取字段名,这些名称中间缺少一个'-'字符:
f1 = np.genfromtxt(fileName1, dtype=None, names=True)
labels = f1.dtype.names[1:]
print labels
> ('HIE_21OPHE_32NH', 'THR_20OPHE_32NH', 'HIE_21ND1PHE_32NH')
代替HIE_21O-PHE_32NH, THR_20O-PHE_32NH, HIE_21ND1-PHE_32NH
为什么?如何检索连字符?
使用参数deletechars=''
:
In [15]: f1 = np.genfromtxt('hyphens.txt', dtype=None, names=True, deletechars='')
In [16]: f1
Out[16]:
array([(1, 0, 0, 0), (2, 1, 0, 0), (3, 0, 0, 0), (4, 0, 0, 0), (5, 0, 0, 0)],
dtype=[('Frame', '<i8'), ('HIE_21@O-PHE_32@N-H', '<i8'), ('THR_20@O-PHE_32@N-H', '<i8'), ('HIE_21@ND1-PHE_32@N-H', '<i8')])
In [17]: f1.dtype.names
Out[17]:
('Frame',
'HIE_21@O-PHE_32@N-H',
'THR_20@O-PHE_32@N-H',
'HIE_21@ND1-PHE_32@N-H')