Re: Rearranging a tensor
- To: mathgroup at smc.vnet.net
- Subject: [mg22486] Re: [mg22433] Rearranging a tensor
- From: BobHanlon at aol.com
- Date: Sun, 5 Mar 2000 00:24:21 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
a = {{1, 2}, {3, 4}}; b = Table[1, {3}, {3}]; c = Outer[Times, a, b]; Join[Sequence @@ #] & /@ Flatten[Transpose /@ c, 1] {{1, 1, 1, 2, 2, 2}, {1, 1, 1, 2, 2, 2}, {1, 1, 1, 2, 2, 2}, {3, 3, 3, 4, 4, 4}, {3, 3, 3, 4, 4, 4}, {3, 3, 3, 4, 4, 4}} Bob Hanlon In a message dated 3/1/2000 2:26:10 AM, noname at noname.com writes: >I have > >In[1]:= a={{1,2},{3,4}}; > >In[2]:= b=Table[1,{3},{3}]; > >In[3]:= c=Outer[Times,a,b] > >Out[3]= {{{{1, 1, 1}, {1, 1, 1}, {1, 1, 1}}, > >> {{2, 2, 2}, {2, 2, 2}, {2, 2, 2}}}, > >> {{{3, 3, 3}, {3, 3, 3}, {3, 3, 3}}, {{4, 4, 4}, {4, 4, 4}, {4, 4, >4}}}} > >In[4]:= c//MatrixForm > >Out[4]//MatrixForm= > 1 1 1 2 2 2 > 1 1 1 2 2 2 > 1 1 1 2 2 2 > > 3 3 3 4 4 4 > 3 3 3 4 4 4 > 3 3 3 4 4 4 > >I would now like to rearrange c so that it is of the form >{{1,1,1,2,2,2},{1,1,1,2,2,2},{1,1,1,2,2,2},{3,3,3,4,4,4},{ 3,3,3,4,4,4},{3,3 >,3,4,4,4}} > >There must be a *simple* way to do this but I cannot see it. Help would >be appreciated. >