astype char conversion

Hi, Sorry if this is silly question, but should this work to convert from int8 to character type? a = array([104, 105], dtype=N.int8) a.astype('|S1') I was a bit surprised by the output: array([1, 1], dtype='|S1') Thanks a lot, Matthew

Matthew Brett wrote:
Hi,
Sorry if this is silly question, but should this work to convert from int8 to character type?
a = array([104, 105], dtype=N.int8) a.astype('|S1')
I'm not sure what you are trying to do here, but the standard coercion to strings will generate ['104', '105']. However you are only allowing 1 character strings so you get the first character. If you are wanting to get characters with ASCII codes 104 and 105 you can do that without coercion by simply viewing the memory as a different data-type: a.view('S1') array([h, i], dtype='|S1') -Travis
participants (2)
-
Matthew Brett
-
Travis Oliphant