RE: options Transpose[] ?

• To: mathgroup at smc.vnet.net
• Subject: [mg49056] RE: [mg48977] options Transpose[] ?
• From: "Wolf, Hartmut" <Hartmut.Wolf at t-systems.com>
• Date: Tue, 29 Jun 2004 04:50:47 -0400 (EDT)
• Sender: owner-wri-mathgroup at wolfram.com

```
>-----Original Message-----
>From: Petr Kujan [mailto:kujanp at fel.cvut.cz]
To: mathgroup at smc.vnet.net
>Sent: Friday, June 25, 2004 11:52 PM
>To: mathgroup at smc.vnet.net
>Subject: [mg49056] [mg48977] options Transpose[] ?
>
>
>Hello Mathematica User Group.
>
>If I have an multidimensional array A:
>
>In[1] :=
>   A = Array[Random[]&, dims = {3,2,4}]
>
>Than I expect that dimension of transposed A with options per
>= {3,1,2}
>is equal  {4,3,2} === dims[[per]] , but it is not equal!
>
>Dimensions of transposed A with options per = {3,1,2} is:
>{2,4,3}.
>
>In[2] :=
>   Dimensions[Transpose[A, per = {3, 1, 2}]]
>   dims[[per]]
>
>It' s correct or it's bug?
>How can I get the same dimensions?
>
>(*-----------------------------------------------------------------------*)
>This is a code for other possible options per in Transpose[A,per] and
>tests if it's equal dims[[per]]:
>
>In[3] :=
>d = Length[dims];
>Dimensions[Transpose[A, #]] == dims[[#]]& /@ Permutations[Range[d]]
>
>I require all elements in True!
>(*-----------------------------------------------------------------------*)
>
>
>
>
>Thanks a lot,
>	     Petr
>
>

Petr,

we have to carefully read the definition (Help > Transpose):

"Transpose[list,{n1, n2, ...}] transposes list so that the k-th level in list is the nk-th level in the result."

This means for Transpose[A, per = {3, 1, 2}]

In[3]:= Dimensions[A]
Out[3]= {3, 2, 4}

The first dimension of A (i.e. 3) becomes the third dimension of the transposed

(_, _, 3)

The second dimension of A (i.e. 2) becomes the first dimension of the transposed

(2, _, 3)

The third dimension of A (i.e. 4) becomes the second dimension of the transposed

(2, 4, 3)

Indeed:

In[5]:= Dimensions[Transpose[A, per = {3, 1, 2}]]
Out[5]= {2, 4, 3}

Such the relationship is just the other way around than you supposed:

In[12]:= Dimensions[Transpose[A, per]][[per]] === Dimensions[A]
Out[12]= True

Or, if you like, expressed as

In[10]:= << DiscreteMath`Combinatorica`

In[13]:= Dimensions[Transpose[A, per]] === Dimensions[A][[InversePermutation[per]]]
Out[13]= True

--
Hartmut Wolf

```

• Prev by Date: RE: Pattern Matching
• Next by Date: RE: PlotLabel with assigned variables *and* on several lines
• Previous by thread: Re: options Transpose[] ?
• Next by thread: Clarification [Re: Overlay graphs ]