5

I want to use this expression for my computation:

FoldList[vt[#2[[1]], #1, #2[[2]], b] &, v0,
Transpose[Join[{ea, cm}]]] 

My problem now is that ea and cm is not only one list each it is a set of lists. How can I make a list of pairs out of these two set of lists?

For example:

ea = {{5, 6, 7}, {1, 2, 3}, {4, 8, 9}} 
cm = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}

and i want a list of pairs of these lists but again in one list each like these:

eacm = 
  {{{5, 1}, {6, 2}, {7, 3}}, {{1, 4}, {2, 5}, {3, 6}}, {{4, 7}, {8, 8}, {9, 9}}}

My real lists are longer than those shown above. I have 720 numbers in each list.

Murta
  • 26,275
  • 6
  • 76
  • 166
user41673
  • 133
  • 6

5 Answers5

11
Transpose[{ea, cm}, {3, 1, 2}]

Flatten[{ea, cm}, {{2}, {3}, {1}}]
Hotoke
  • 156
  • 1
  • 2
6

This is not an answer, but an extended comment on Hotoke's answer.

The OP seems to think Transpose isn't applicable when ea and cm are very long lists, say, of 10000 triples each. Perhaps the OP thinks it would be very slow is such a case. But actually it is very fast even for long lists, as I will demonstrate here.

SeedRandom[42];
With[{n = 10000, k = 12},
  Module[{m, mt, t},
    m = RandomInteger[42, {2, n, 3}];
    t = AbsoluteTiming[mt = Transpose[m, {3, 1, 2}]][[1]];
    {t, Column[{#, mt[[#]]} & /@ RandomSample[Range[n], k]]}]]

result

It still works well even if the sublists are longer. Here is example with 5-tuples.

SeedRandom[42];
With[{n = 10000, i = 5, k = 8},
  Module[{m, mt, t},
    m = RandomInteger[42, {2, n, i}];
    t = AbsoluteTiming[mt = Transpose[m, {3, 1, 2}]][[1]];
    {t, Column[{#, mt[[#]]} & /@ RandomSample[Range[n], k]]}]]

result

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
5

Does it fit your needs?

MapThread[List, {ea, cm}, 2]
Kuba
  • 136,707
  • 13
  • 279
  • 740
2

Example

Transpose @ # & /@ Transpose[{ea, cm}]

Note: ea and cm same as in original post

e.doroskevic
  • 5,959
  • 1
  • 13
  • 32
2

Transpose second argument is like magic/cryptic for me. Here is another option using Map:

Map[Transpose, Transpose@{ea, cm}, {-3}]
Murta
  • 26,275
  • 6
  • 76
  • 166