Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

It is very likely that it is my lack of math skills that is showing up here. However, I think Transpose is such an important function that I need to master it. So I am going to ask because I do not understand the information given in the documentation.

Transpose[list,{Subscript[n, 1], Subscript[n, 2], …}] transposes list so that the k-th level in list is the Subscript[n, k]-th level in the result.

Would anyone be able to provide a simple example and point out in a matrix what is going on? I am in particular struggling with the nth and k-th level. How does that work?

I want to master Transpose[list, {…}]. Please explain the case where the k-th and n-th level are to be transposed, since this is where I am struggling.

If this is considered mathematical question, and therefore not in the right place, I would appreciate a comment so that I could delete the post.

share|improve this question
    
There are copious examples in the Scope section of the function in the documentation. Look at the results (the pattern of indexes in particular) of those results, should be clear. –  rasher Apr 13 at 0:15
    
As a mathematical question, "What is the transpose?" is actually pretty complex. In short, it's a canonical isomorphism between $V\otimes W^*$ and $V^*\otimes W$ that exists whenever $V,W$ are Hilbert spaces. –  Alex Becker Apr 13 at 6:07
    
Transpose[$m, {3, 2, 1}] === Flatten[$m, {{3}, {2}, {1}}], so you might find this discussion of Flatten useful. –  WReach Apr 13 at 14:54

2 Answers 2

up vote 9 down vote accepted

Here is a visualization of the 3 dimensional case. A part of the tensor is indexed by

`tensor[[l1, l2, l3]]`

where l1, l2, l3 are the indices to levels 1, 2, 3 respectively. Transposing switches how the values are indexed. For example, if new = Transpose[old, {2, 3, 1}], then new[[l3, l1, l2]] == old[[l1, l2, l3]] or new[[l1, l2, l3]] == old[[l2, l3, l1]]. The first equality corresponds to how the result is described in Transpose.

In the visualization below, the colors are transposed according to the permutation labeling the graphics. Level 1 corresponds to hue, level 2 to saturation, and level 3 to brightness. The upper left is the identity permutation and corresponds to the original tensor. The labels on the axes correspond to the level in the original tensor.

tensor = Table[{i, j, k}, {i, 4}, {j, 4}, {k, 4}];
cf[i_, j_, k_] := Hue[(i - 1)/4, j/4, (k + 3)/9];
g[p_] := Graphics3D[{
    PointSize[0.1],
    Point[Flatten[tensor, 2], 
     VertexColors -> cf @@@ Flatten[Transpose[tensor, p], 2]]
    },
   PlotRange -> {{0.8, 4.2}, {0.8, 4.2}, {0.8, 4.2}},
   PlotLabel -> p,
   Axes -> True, Ticks -> None,
   AxesLabel -> Ordering@p
   ];

GraphicsGrid[Partition[Table[g[p], {p, Permutations[{1, 2, 3}]}], 3]]

Mathematica graphics

I hope that this example will help with understanding how higher dimensional tensors are transposed.

share|improve this answer

This is more of a math question, but in the spirit of being helpful:

I think if you run this code and look at the colors of each matrix you might understand better what transpose does.

    m = Table[Graphics[{RGBColor[0, .33 i, .33 j], Disk[]}], {i, 1, 3},
     {j,1,3}] // MatrixForm;
    mT = Transpose@Table[Graphics[{RGBColor[0, .33 i, .33 j], Disk[]}],
     {i, 1, 3}, {j, 1, 3}] // MatrixForm;
    Row[{m, mT}]

Transpose basically reflects elements across the diagonal.

Notice how the first column of the original matrix is the same as the first row of the transposed matrix.

share|improve this answer
2  
I think the OP had in mind the syntax with the second argument of Transpose, which allows complex array reshuffles for arrays of higher dimensions, rather than the (trivial) single-arg Transpose. –  Leonid Shifrin Apr 13 at 2:32

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.