Re: How to remove all cycles
- To: mathgroup at smc.vnet.net
- Subject: [mg98316] Re: [mg98269] How to remove all cycles
- From: Bob Hanlon <hanlonr at cox.net>
- Date: Sun, 5 Apr 2009 06:41:08 -0400 (EDT)
- Reply-to: hanlonr at cox.net
n = 13; A = Array[a, 2^(n + 1)]; B = Array[b, {2, 2^n}]; Do[Do[A[[j + BitShiftLeft[k - 1, 1]]] = B[[j, k]], {j, 1, 2}], {k, 1, 2^n}] // Timing {0.616373,Null} A2 = Flatten[Transpose[B]]; // Timing {0.008281,Null} A == A2 True Bob Hanlon ---- buts <manger31 at yahoo.com> wrote: ============= Hello, I want to write the following code using functional programming, i.e. to remove all Do's. There are two arrays: A[[i]], i=1,...,2^(n+1) B[[j,k]], j=1,2; k=1,...,2^n. I need to assign B to A setting the first bit of the index i to be the index j. Explicitly Do[Do[A[[ j + BitShiftLeft[k-1,1] ]]= B[[j,k]], {j,1,2}],{k,1,2^n}] I need to do it for multi-dimensional large arrays. Is it possible to write it without Do's ? Thanks. -- Bob Hanlon