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


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

Re: How to create this kind of list

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

Show all headers | View raw


On 10/15/2011 6:08 AM, Szymon Roziewski wrote:
> Hello there,
> I am thinking about creating such a list.
> I have 2 lists with the same number of elements.
> The idea is to create one list which was taken from these previous two ones
> in the following way:
> Take one element of the first list and one from another and put it into
> result list {{x1,y1},{x2,y2},...,{xn,yn}}.
> Input lists:
> A={x1,x2,...,xn}
> B={y1,y2,...,yn}
>
> All best,
> Szymon Roziewski

Here are two ways. (And BTW, it helps when you post here to include an 
example that others can copy/paste into Mathematica instead of having 
make up an example for you.) Anyway, let's make a couple of lists:


list1 = RandomInteger[10, 5]

list2 = RandomInteger[{15, 20}, 5]

One method: Use Riffle to make a new list alternating elements from 
list1 and list2, then Partition into pairs, like so.

Partition[Riffle[list1, list2], 2]

Second method: Put list1 and list2 into matrix with list1 as the first 
row and list2 as the second row, then Transpose the matrix.

Transpose[{list1, list2}]


-- 
Helen Read
University of Vermont

Back to comp.soft-sys.math.mathematica | Previous | Next — Previous in thread | Next 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