MathGroup Archive 2004

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: options Transpose[] ?


Petr Kujan <kujanp at fel.cvut.cz> wrote in message 
news:<cbi6v2$lb6$1 at smc.vnet.net>...
> 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?
> [...]

Mathematica treats per as a "TO" list, in which the i-th value 
specifies which new dimension the old i-th dimension goes TO. 
It interprets {3,1,2} as meaning that 
old dimension 1 --> new dimension 3,
old dimension 2 --> new dimension 1,
old dimension 3 --> new dimension 2.

You're treating per as a "FROM" list, in which the i-th value 
specifies which old dimension the new i-th dimension comes FROM:
you want {3,1,2} to mean that
new dimension 1 <-- old dimension 3,
new dimension 2 <-- old dimension 1,
new dimension 3 <-- old dimension 2.

In this case, per = {2,3,1} will get you what you want. More generally,

convert[per_] := Last@Transpose@Sort@Transpose@{per,Range@Length@per}

will convert one form of permutation list to the other.


  • Prev by Date: AW: more question about plotting
  • Next by Date: PlotLabel with assigned variables *and* on several lines
  • Previous by thread: options Transpose[] ?
  • Next by thread: Re: Re: options Transpose[] ?