Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2011

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

Search the Archive

Re: How to create this kind of list

  • To: mathgroup at smc.vnet.net
  • Subject: [mg122149] Re: How to create this kind of list
  • From: dimitris <dimmechan at yahoo.com>
  • Date: Sun, 16 Oct 2011 07:08:35 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <j7bm30$35r$1@smc.vnet.net>

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