I have to change a string dictionary which kind of looks like this.
result = {'top-L': ' ', 'top-M': ' ', 'top-R': ' ',
'mid-L': ' ', 'mid-M': ' ', 'mid-R': ' ',
'low-L': ' ', 'low-M': ' ', 'low-R': ' '}
Now, i have to convert this into a 3x3 array.
So, far i have reached a code which do almost what i intended but still its messy.
Here is the code.
import numpy as np
names = ['left','middle']
formats = ['S3','S3']
dtype = dict(names = names, formats=formats)
array = np.fromiter(result.items(), dtype=dtype, count=len(result))
arr = np.reshape(array, (3,3))
print(repr(arr))
print (arr[0][1])
and the output which generated.
array('lo[[(b'top', b' '), (b'top', b' '), (b'top', b' ')],
[(b'mid', b' '), (b'mid', b' '), (b'mid', b' ')],
[(b'low', b' '), (b'low', b' '), (bw', b' ')]],
dtype=[('left', 'S3'), ('middle', 'S3')])
(b'top', b' ')
note print (arr[0][1]) generates (b'top', b' ') which is not expected.
There might be something wrong with this code, any suggestions.