Thursday, 12 September 2013

numpy array of strings indexing behavior

numpy array of strings indexing behavior

I have an array of strings
>>> lines
array(['RL5\\Stark_223', 'RL5\\Stark_223', 'RL5\\Stark_223', ...,
'RL5\\Stark_238', 'RL5\\Stark_238', 'RL5\\Stark_238'],
dtype='|S27')
Why can I index into a string for the first array element
>>> lines[0][0:3]
'RL5'
But not into the same place for all array elements
>>> lines[:][0:3]
array(['RL5\\Stark_223', 'RL5\\Stark_223', 'RL5\\Stark_223'],
dtype='|S27')
Can anyone suggest a method to get the following result:
array(['RL5', 'RL5', 'RL5', ...'RL5', 'RL5')

No comments:

Post a Comment