Consider I have an array containing the string of datetime:
new_time[index]
Out[9]:
array(['2012-09-01_00:00:00', '2012-09-01_01:00:00',
'2012-09-01_02:00:00', '2012-09-01_03:00:00',
'2012-09-01_04:00:00', '2012-09-01_05:00:00',
'2012-09-01_06:00:00', '2012-09-01_07:00:00',
'2012-09-01_08:00:00', '2012-09-01_09:00:00',
'2012-09-01_10:00:00', '2012-09-01_11:00:00',
'2012-09-01_12:00:00', '2012-09-01_13:00:00',
'2012-09-01_14:00:00', '2012-09-01_15:00:00',
'2012-09-01_16:00:00', '2012-09-01_17:00:00',
'2012-09-01_18:00:00', '2012-09-01_19:00:00',
'2012-09-01_20:00:00', '2012-09-01_21:00:00',
'2012-09-01_22:00:00', '2012-09-01_23:00:00'], dtype='<U19')
Its shape is (24,).The question is how can I assign it to a (24,19)array,and the rows of new array could look like following:
## one row of new array
Out[10]:
array([[b'2', b'0', b'1', b'2', b'-', b'0', b'9', b'-', b'0', b'1', b'_',
b'0', b'0', b':', b'0', b'0', b':', b'0', b'0']], dtype='|S1')
Thanks for your help.
X.view('U1').reshape(X.size, -1).astype('S1').dtype='U1'work, butdtype='S1'does not?U*toS1every character gets distributed across 4 bytes. To get fromUtoSyou have to use something likeastype, i.e. actually create a new data buffer with the unicode characters expressed as single bytes.X.view('S1').reshape(X.size, -1, 4)[..., 0]