Re: A question about pattern-matching
- To: mathgroup at smc.vnet.net
- Subject: [mg63754] Re: [mg63728] A question about pattern-matching
- From: ggroup at sarj.ca
- Date: Fri, 13 Jan 2006 04:48:44 -0500 (EST)
- References: <djcgcs$6du$1@smc.vnet.net> <200510230946.FAA10826@smc.vnet.net> <200601120822.DAA10486@smc.vnet.net>
- Reply-to: ggroup at sarj.ca
- Sender: owner-wri-mathgroup at wolfram.com
On Thursday, January 12, 2006 at 03:22 GMT -0500, Gardyloo wrote: <snip> > First, a small subset of the data: > testList = {{-90, {{60493, 0.061}, {62493, 0.15881}, {64493.5, > 0.559}}}, {-88, {{62493, 0.151}, {64493., 0.61617}, {65993.4, > 0.171}, {68993.10, 0.06}}}, {-86, {{62493.75, 0.14}, {64493.55, > 0.61440}, {65993., 0.18}, {67993, 0.0}, {68993.100, 0.06448}}}}; > The data consists of lists of the form { integer, { ordered pair1, > ordered pair2, ... } }, and my goal is to extract the second number in > each of the ordered pairs, while retaining the lists' overall structure. What about using Part? I think you get exactly what you want with: testList[[All,2,All,2]] > So, for example, from testList, I'd want something like > { { 0.061, 0.15881, 0.559}, {0.151, 0.61617, 0.171, 0.06}, {0.14, > 0.61440, 0.18, 0.0, 0.06448}} > returned. In[1]:= testList = {{-90, {{ 60493, 0.061}, { 62493, 0.15881}, {64493.5, 0.559}}}, {-88, {{62493, 0.151}, {64493., 0.61617}, {65993.4, 0.171}, {68993.10, 0.06}}}, {-86, {{62493.75, 0.14}, {64493.55, 0.61440}, {65993., 0.18}, {67993, 0.0}, {68993.100, 0.06448}}}}; In[2]:= testList[[All, 2, All, 2]] Out[2]= {{0.061, 0.15881, 0.559}, {0.151, 0.61617, 0.171, 0.06}, {0.14, 0.6144, 0.18, 0., 0.06448}} In[3]:= %=={{0.061, 0.15881, 0.559}, {0.151, 0.61617, 0.171, 0.06}, {0.14, 0.61440, 0.18, 0.0, 0.06448}} Out[3]= True
- References:
- A question about pattern-matching
- From: gardyloo <gardyloo@mail.wsu.edu>
- A question about pattern-matching