MathGroup Archive 2011

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

Search the Archive

Re: How to create this kind of list


There are several ways to do this. You should check what is the more
efficient!

Say the 2 lists are the following:

lst1 = Table[Random[Integer, {-100, 100}], {10}]
{-14, -62, 2, 63, -9, 78, -76, 1, -98, 26}

lst2 = Table[Random[Integer, {-100, 100}], {10}]
{-60, -98, 31, 66, -97, 47, 18, -40, 94, -76}

Then one way to proceed is:

({lst1[[#1]], lst2[[#1]]} & ) /@ Range[Length[lst1]]
{{-14, -60}, {-62, -98}, {2, 31}, {63, 66}, {-9, -97}, {78, 47}, {-76,
18}, {1, -40}, {-98, 94}, {26, -76}}

Another way is the following:

Transpose[{lst1, lst2}]
{{-14, -60}, {-62, -98}, {2, 31}, {63, 66}, {-9, -97}, {78, 47}, {-76,
18}, {1, -40}, {-98, 94}, {26, -76}}

A third way is:

Thread[{lst1, lst2}]
{{-14, -60}, {-62, -98}, {2, 31}, {63, 66}, {-9, -97}, {78, 47}, {-76,
18}, {1, -40}, {-98, 94}, {26, -76}}

Similarly,

MapThread[List, {lst1, lst2}]
{{-14, -60}, {-62, -98}, {2, 31}, {63, 66}, {-9, -97}, {78, 47}, {-76,
18}, {1, -40}, {-98, 94}, {26, -76}}

Best Regards
Dimitris



  • Prev by Date: Re: Sliding Time Window Function
  • Next by Date: Re: How to create this kind of list
  • Previous by thread: Re: How to create this kind of list
  • Next by thread: Re: How to create this kind of list