0

I am trying to read the following file and I tried to use numpy to load data:

#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

If I read the field names from the 1st row starting with the first value, the names are missing a '-' character from the middle:

f1 = np.genfromtxt(fileName1, dtype=None, names=True)
labels = f1.dtype.names[1:]
print labels

> ('HIE_21OPHE_32NH', 'THR_20OPHE_32NH', 'HIE_21ND1PHE_32NH')

instead of HIE_21O-PHE_32NH, THR_20O-PHE_32NH, HIE_21ND1-PHE_32NH

Why? How can I retrieve the hyphen?

Warren Weckesser
  • 110,654
  • 19
  • 194
  • 214
kris
  • 1
  • 1
  • The default action modifies the names to they can function as attribute names (for `recarrays`). – hpaulj Aug 15 '16 at 15:36

1 Answers1

2

Use the argument 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')
Warren Weckesser
  • 110,654
  • 19
  • 194
  • 214