Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #5682

Re: How to create this kind of list

From dimitris <dimmechan@yahoo.com>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: How to create this kind of list
Date 2011-10-16 11:17 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <j7eefq$el5$1@smc.vnet.net> (permalink)
References <j7bm30$35r$1@smc.vnet.net>

Show all headers | View raw


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

Back to comp.soft-sys.math.mathematica | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

How to create this kind of list Szymon Roziewski <szymon.roziewski@gmail.com> - 2011-10-15 10:08 +0000
  Re: How to create this kind of list Helen Read <readhpr@gmail.com> - 2011-10-16 11:08 +0000
  Re: How to create this kind of list "Oleksandr Rasputinov" <oleksandr_rasputinov@hmamail.com> - 2011-10-16 11:11 +0000
  Re: How to create this kind of list "Dr. Wolfgang Hintze" <weh@snafu.de> - 2011-10-16 11:16 +0000
  Re: How to create this kind of list dimitris <dimmechan@yahoo.com> - 2011-10-16 11:17 +0000

csiph-web