MathGroup Archive 2008

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

Search the Archive

Re: List re-arrangement question

  • To: mathgroup at smc.vnet.net
  • Subject: [mg87748] Re: List re-arrangement question
  • From: Szabolcs Horvát <szhorvat at gmail.com>
  • Date: Wed, 16 Apr 2008 06:50:33 -0400 (EDT)
  • Organization: University of Bergen
  • References: <fu4fkm$nip$1@smc.vnet.net>

Yaroslav Bulatov wrote:
> I'm trying to do something like the following:
> Transpose[{{{a1, a2, a3}, {a1}, {a1, a2, a3}}, {{b1, b2, b3}, {b1},
> {b1, b2, b3}}}, {3, 1, 2}]
> 
> expecting to get:
> {{{a1, b1}, {a2, b2}, {a3, b3}}, {{a1, b1}}, {{a1, b1}, {a2, b2}, {a3,
> b3}}}
> 
> However, it looks like Transpose doesn't work with "ragged"
> arrays...so what is the recommended Mathematica style to do the above
> transformation?
> 

Hi Yaroslav,

Thread[] is very similar to Transpose[] (in fact completely equivalent 
for matrices), but it is more difficult to use with multidimensional 
arrays.  On the up side, it works fine with ragged arrays :-)

In[1]:= xx = {{{a1, a2, a3}, {a1}, {a1, a2, a3}}, {{b1, b2,
     b3}, {b1}, {b1, b2, b3}}}

Out[1]= {{{a1, a2, a3}, {a1}, {a1, a2, a3}}, {{b1, b2, b3}, {b1}, {b1,
     b2, b3}}}

In[2]:= Thread[xx]

Out[2]= {{{a1, a2, a3}, {b1, b2, b3}}, {{a1}, {b1}}, {{a1, a2,
    a3}, {b1, b2, b3}}}

In[3]:= Thread /@ %

Out[3]= {{{a1, b1}, {a2, b2}, {a3, b3}}, {{a1, b1}}, {{a1, b1}, {a2,
    b2}, {a3, b3}}}

Szabolcs


  • Prev by Date: If Integrate returns no result, can we conclude that no closed-form
  • Next by Date: Re: DifferenitalD vs CapitalDifferenitalD
  • Previous by thread: Re: List re-arrangement question
  • Next by thread: Re: List re-arrangement question