[Numpy-discussion] Rotate Left and Rotate Right

Cristi Constantin darkgl0w@yahoo....
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:
i want
to go
to the

Rotated right would be:
a  w
 e t

Rotated left would be:
t e 
w  a

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...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20090520/874b32f6/attachment.html 

More information about the Numpy-discussion mailing list