Transpose


Transpose can be used on tensors as well as on matrices and the expressions
don't have to be nested lists either.

By using the second argument of Transpose you can control the levels that are
transposed.

Clear[a, b, c, d, e, f, g, h] ;  tt = {{{{1, a}, {2, b}}, {{3, c}, {4, d}}}, {{{5, e}, {6, f}}, {{7, g}, {8, h}}}} ;   MatrixForm[tt]

( ( 1   a )   ( 3   c ) )                      ... 5   e )   ( 7   g )                      6   f                       8   h

Transpose[tt]//MatrixForm

( ( 1   a )   ( 5   e ) )                      ... 3   c )   ( 7   g )                      4   d                       8   h

Transpose[tt, {1, 2, 4, 3}]//MatrixForm

( ( 1   2 )   ( 3   4 ) )                      ... 5   6 )   ( 7   8 )                      e   f                       g   h

Transpose[tt, {2, 1, 4, 3}]//MatrixForm

( ( 1   2 )   ( 5   6 ) )                      ... 3   4 )   ( 7   8 )                      c   d                       g   h


Tr will do the same as the following, but faster when done with a large
expression.

Transpose[tt, {1, 1}]//MatrixForm

( ( 1 )   ( 2 ) )                      a       ...       ( 7 )   ( 8 )                      g                       h


Created by Mathematica  (May 16, 2004)

Back to Ted’s Tricks index page