Created
July 18, 2012 10:34
-
-
Save Jim-Holmstroem/3135464 to your computer and use it in GitHub Desktop.
itertools.foo(*A)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from itertools import * | |
def matrix_range(N,M): | |
return map(lambda i: range(i,i+M),range(0,N*M,M)) #Create a MxN matrix (for testing) | |
A=matrix_range(5,3) | |
At=zip(*A) #transpose | |
At2=map(list,zip(*A)) #transpose without the tuple problems (slower) | |
At3=map(list,izip(*A)) #could be faster for big lists | |
a=chain(*A) #flatten to vector, lazyversion: http://docs.python.org/library/itertools.html#itertools.chain.from_iterable |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment