I have a numpy 2D-array of string with shape (3,2):
ar_2d = array([['123', '456'],
['789', '0ab'],
['cde', 'fgh']],
dtype='<U3')
To make it easier, I am sure the length of each string is equal.
And I have a function, i.e. namely split(), to make string '123' to python list ['1','2','3']
Now I would like to produce a 3D-array with '123' to an array array(['1', '2', '3']) and finally I can get a 3D-array with shape (3,2,3):
ar_3d = array([[['1', '2', '3'],
['4', '5', '6']],
[['7', '8', '9'],
['0', 'a', 'b']],
[['c', 'd', 'e'],
['f', 'g', 'h']]],
dtype='<U1')
I have an idea that splitting the string to list first and write to file with numpy's format. Then, I shall read the array from the file.
If the elements are integer numbers, would it be easier? i.e. number 123 to list [1,2,3]
So here is the problem, is there an elegant method to do the convertion?
Thanks in advance!