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


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

Re: Changing a list with the information of other

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!news.glorb.com!news-out.readnews.com!news-xxxfer.readnews.com!newspump.sol.net!posts.news.twtelecom.net!nnrp3.twtelecom.net!not-for-mail
From Tomas Garza <tgarza10@msn.com>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Changing a list with the information of other
Date Wed, 3 Jul 2013 08:48:42 +0000 (UTC)
Sender steve@smc.vnet.net
Approved Steven M. Christensen <steve@smc.vnet.net>, Moderator
Message-ID <kr0oha$3do$1@smc.vnet.net> (permalink)
References <20130702044642.9CA146A4F@smc.vnet.net>
Lines 34
Organization Time-Warner Telecom
NNTP-Posting-Date 03 Jul 2013 08:50:41 GMT
NNTP-Posting-Host dd7bedb9.news.twtelecom.net
X-Trace DXC=XlWFCA0_40B\UDZWb:DFIDC_A=>8kQj6MMOj3YM9`=aHfDD@SIi<R3AEFiONJ7[GoFI:]M_Kn3;4@
X-Complaints-To abuse@twtelecom.net
Xref csiph.com comp.soft-sys.math.mathematica:15099

Show key headers only | View raw


A possible approach, using the power of functional programming, is
In[1]:= listone={{0,1},{1,w},{2,1+w},{3,1+2 w},{4,2},{5,2 w},{6,2+2 w},{7,2+w}}Out[1]= {{0,1},{1,w},{2,1+w},{3,1+2 w},{4,2},{5,2 w},{6,2+2 w},{7,2+w}}
In[2]:= listtwo={1,1+w,2+w,2 w,2,2+2 w,1+2 w,w}Out[2]= {1,1+w,2+w,2 w,2,2+2 w,1+2 w,w}
In[3]:= listthree=Transpose[listone][[2]]Out[3]= {1,w,1+w,1+2 w,2,2 w,2+2 w,2+w}
In[4]:= pos=Flatten[Position[listthree,#,{1}]&/@listtwo]Out[4]= {1,3,8,6,5,7,4,2}
In[5]:= listone[[pos[[#]]]][[1]]&/@Range[Length[pos]]Out[5]= {0,2,7,5,4,6,3,1}
-Tomas

> From: jen@fct.unl.pt
> Subject: Changing a list with the information of other
> To: mathgroup@smc.vnet.net
> Date: Tue, 2 Jul 2013 00:46:42 -0400
>
> Good morning
>
> I have the following (possibly very simple) problem.
> I have a list, created using a Table
>
> {{0, 1}, {1, w}, {2, 1 + w}, {3, 1 + 2 w}, {4, 2}, {5, 2 w}, {6, 2 + 2 w}, {7, 2 + w}}.
>
> Then, using another Table, I created the list
>
> {1, 1 + w, 2 + w, 2 w, 2, 2 + 2 w, 1 + 2 w, w}
>
> Note that all these elements appear always in second place, in the ordered pairs of the first list. What I want is an instruction that allows to replace all these elements by the ones that appear first in the ordered pairs above. That is, I would like to replace this list by the new one
>
> {0, 2, 7, 5, 4, 6, 3, 1}.
>
> As you may guess this is only of interest when the lists are very big (with thousands of elements).
>
> Thank you
>
 		 	   		  

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


Thread

Re: Changing a list with the information of other Tomas Garza <tgarza10@msn.com> - 2013-07-03 08:48 +0000

csiph-web