[Numpy-discussion] Rotate Left and Rotate Right
Wed May 20 06:53:25 CDT 2009
Good day, me again.
I have this string of data :
String = 'i want\nto go\nto the\nbeach'.
I want to rotate this data to left, or to right, after is split it after '\n'.
Note that it's important to use 'U' array, because i might have unicode characters in this string.
So normal, the text is:
Rotated right would be:
Rotated left would be:
There are a few methods i guess could be used.
Split like: [np.array([j for j in i],'U') for i in String.split('\n')] =>
[ array([u'i', u' ', u'w', u'a', u'n', u't'], dtype='<U1'),
array([u't', u'o', u' ', u'g', u'o'], dtype='<U1'),
array([u't', u'o', u' ', u't', u'h', u'e'], dtype='<U1'),
array([u'b', u'e', u'a', u'c', u'h'], dtype='<U1') ]
Or split like: np.array( String.split('\n'), 'U' ), => array([u'i want', u'to go', u'to the', u'beach'], dtype='<U6')
Both methods are impossible to use with my knowledge.
Without Numpy, if i want to rotate to right: i should reverse a list of splited by '\n' strings, save max length for all lines, align all lines to max len, rotate the square with map( lambda *row: [elem for elem in row], *Content ), then join the resulted sub-lists, unite with '\n' and return.
I need to know if there is a faster Numpy approach... maybe explode the string by '\n' and rotate fast, or something?
Thank you very much, in advance.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Numpy-discussion