|
From: kevin on 1 Jun 2010 04:23 Hi Guys, I am a newbie to mathematica..Is there anyway to read values from 2 lists {n by 1} and {n by 1} to a new list {n by 2} without using loops.. eg say you have x = {1,3,5} any y = {2,4,6}, I will need a new list z ={{1,2},{3,4},{5,6}}.. Thanks in advance.
From: Simon Pearce on 1 Jun 2010 07:40 Try, x == {1,3,5};y=={2,4,6}; Partition[Riffle[x, y], 2] Simon -----Original Message----- From: kevin [mailto:kevin999koshy(a)gmail.com] Sent: 01 June 2010 09:24 Subject: Assigning values to a list. Hi Guys, I am a newbie to mathematica..Is there anyway to read values from 2 lists {n by 1} and {n by 1} to a new list {n by 2} without using loops.. eg say you have x == {1,3,5} any y == {2,4,6}, I will need a new list z =={{1,2},{3,4},{5,6}}.. Thanks in advance. This message has been checked for viruses but the contents of an attachment may still contain software viruses which could damage your computer system: you are advised to perform your own checks. Email communications with the University of Nottingham may be monitored as permitted by UK legislation.
From: Raffy on 1 Jun 2010 07:40 On Jun 1, 1:23 am, kevin <kevin999ko...(a)gmail.com> wrote: > Hi Guys, > > I am a newbie to mathematica..Is there anyway to read > values from 2 lists {n by 1} and {n by 1} to a new list {n by 2} > without using loops.. eg say you have x = {1,3,5} any y = {2,4,6}, I > will need a new list z ={{1,2},{3,4},{5,6}}.. Thanks in advance. Transpose@{x,y} Or more customizable: MapThread[List,{x,y}] (where List could be a different function)
From: Thomas Dowling on 1 Jun 2010 07:41 Hello, x = {1, 3, 5} y = {2, 4, 6} Transpose[{x, y}] MapThread[List, {x, y}] Flatten[{x, y}, {2}] Note that Flatten will transpose a 'ragged' list Flatten[{x, {a, b, c, d}}, {2}] Tom Dowling On Tue, Jun 1, 2010 at 9:24 AM, kevin <kevin999koshy(a)gmail.com> wrote: > Hi Guys, > > I am a newbie to mathematica..Is there anyway to read > values from 2 lists {n by 1} and {n by 1} to a new list {n by 2} > without using loops.. eg say you have x = {1,3,5} any y = {2,4,6}, I > will need a new list z ={{1,2},{3,4},{5,6}}.. Thanks in advance. > >
From: Michael Stern on 1 Jun 2010 07:41 You will get a lot of responses to this. If the lists are the same length, you can do it easily. z==Transpose[{x,y}] Michael On Jun 1, 2010, at 4:24 AM, kevin wrote: > Hi Guys, > > I am a newbie to mathematica..Is there anyway to read > values from 2 lists {n by 1} and {n by 1} to a new list {n by 2} > without using loops.. eg say you have x == {1,3,5} any y == {2,4,6}, I > will need a new list z =={{1,2},{3,4},{5,6}}.. Thanks in advance. >
|
Next
|
Last
Pages: 1 2 Prev: Graphics3D question Next: difficulty in calculating first two terms of an infinite sum |