MathGroup Archive 2003

[Date Index] [Thread Index] [Author Index]

Search the Archive

RE: more with lists

  • To: mathgroup at smc.vnet.net
  • Subject: [mg40343] RE: [mg40326] more with lists
  • From: "Wolf, Hartmut" <Hartmut.Wolf at t-systems.com>
  • Date: Wed, 2 Apr 2003 04:35:46 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

>-----Original Message-----
>From: Nathan Moore [mailto:nmoore at physics.umn.edu]
To: mathgroup at smc.vnet.net
>Sent: Tuesday, April 01, 2003 11:53 AM
>To: mathgroup at smc.vnet.net
>Subject: [mg40343] [mg40326] more with lists
>
>
>The replies have been beautiful!
>
>suppose I have a list of n {x,y}pairs.  I'd like to cull the 
>list into a
>smaller list for which the condition x<Xo, y>Yo is true.  If 
>the list was
>1-D I could simply use "Select," how do I access the data 
>points in pairs?
>
>Nathan Moore
>Universoty of Minnesota Physics
>
>

Still use Select!

In[29]:= ll = Table[{Random[], i*.1 + Random[]}, {i, 25}]
Out[29]=
{{0.729666, 0.704118}, {0.623234, 0.349074}, {0.81287, 1.18585}, {0.626257, 
    0.649148}, {0.668199, 0.879212}, {0.461906, 1.28604}, {0.413234, 
    1.34433}, {0.719861, 0.920554}, {0.460918, 1.35331}, {0.773022, 
    1.02309}, {0.502923, 1.36225}, {0.759855, 2.08335}, {0.773257, 
    1.95813}, {0.136621, 2.13427}, {0.960387, 2.27228}, {0.510364, 
    2.08513}, {0.292188, 2.09307}, {0.0484584, 2.59908}, {0.878954, 
    2.64874}, {0.328597, 2.67853}, {0.418037, 2.39543}, {0.555575, 
    2.85544}, {0.915114, 2.33318}, {0.79572, 3.17209}, {0.141857, 2.87505}}

In[30]:= Select[ll, #[[1]] < .7 && #[[2]] > 1. &]
Out[30]=
{{0.461906, 1.28604}, {0.413234, 1.34433}, {0.460918, 1.35331}, {0.502923, 
    1.36225}, {0.136621, 2.13427}, {0.510364, 2.08513}, {0.292188, 
    2.09307}, {0.0484584, 2.59908}, {0.328597, 2.67853}, {0.418037, 
    2.39543}, {0.555575, 2.85544}, {0.141857, 2.87505}}


Or equally do:

Cases[ll, {a_, b_} /; a < .7 && b > 1.]

Cases[ll, {_?(# < .7 &), _?(# > 1. &)}]

DeleteCases[ll, {a_, b_} /; a >= .7 || b <= 1.]


--
Hartmut Wolf



  • Prev by Date: Re: generate random permutation
  • Next by Date: Re: Opinions about the "Oneliners"
  • Previous by thread: Re: more with lists
  • Next by thread: Re: Help-directional fields