How to make a matrix tu in one line without Numpy and cycles?
For example, if the original matrix:
[ 1 , 2 ], [ 3 , 4 ]] then the resulting should be:
[ 3 , 1 ], [ 4 , 2 ]] PREA>
question@mail.ru
·
01.01.1970 03:00
How to make a matrix tu in one line without Numpy and cycles?
For example, if the original matrix:
[ 1 , 2 ], [ 3 , 4 ]] then the resulting should be:
[ 3 , 1 ], [ 4 , 2 ]] PREA>
answer@mail.ru
·
01.01.1970 03:00
I found a rather elegant way to make a matrix tu in one line without Numpy and cycles. In Runet, I could not find anything sensible, it can help someone. Original here:
Rotated = zip (*Original [::- 1 ]) class = ""># python 2 roted = tuple ( zip span> (*Original [::- 1 ]))) # Python 3 how it works.
Original = [ 1 , 2 ], [ 3 , 4 ]]
& Gt; & Gt; & GT; Original [::- 1 ] [ 3 , 4 ], [ 1 , 2 ]] pre> and then this already wrapped list is transmitted to the functions of the zip ()
zip ([ 3 , 4 ], [ 1 , 2 ]) # ^ ^ ^ ^ --- Column 2 #------ Column 1 I hope someone is useful, and then they begin to begin Busting through built -in cycles, etc.