Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.math.mathematica

Topic: [mg5387] select a range of elements from a nested list
Replies: 0  

Advanced Search

Back to Topic List Back to Topic List  
Allan Hayes

Posts: 1,508
Registered: 12/6/04
[mg5387] select a range of elements from a nested list
Posted: Dec 6, 1996 11:43 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Oliver Schurr <schurro@gusun.acc.georgetown.edu>
Subject: [mg5387] select a range of elements from a nested list

>Say you have a nested list like that
>{{x1,y1},{x2,y2},{x3,y3},...{xn,yn}}
> ... and you ONLY want to select the elements (x,y values) from

the >list for which the x value spans say 0 to 0.3.

Olver,
Select or Cases with appropriate tests seem to be what you need.

Examples:

lst = Table[Random[],{1000},{2}];

Select[lst, (#[[1]]<0.01)&]//Timing
{0.45 Second,
{{0.00392864, 0.312819}, {0.00878624, 0.683771},
{0.00347346, 0.651138}, {0.00705477, 0.599932},
{0.00617553, 0.827159}, {0.00227771, 0.373836},
{0.00679162, 0.128556}, {0.0051724, 0.947127},
{0.00839845, 0.612825}}
}

Cases[lst, {x_,y_}/;x<0.1]//Timing

{0.35 Second,
{{0.00392864, 0.312819}, {0.00878624, 0.683771},
{0.00347346, 0.651138}, {0.00705477, 0.599932},
{0.00617553, 0.827159}, {0.00227771, 0.373836},
{0.00679162, 0.128556}, {0.0051724, 0.947127},
{0.00839845, 0.612825}}
}

Allan Hayes
hay@haystack.demon.co.uk
http://www.haystack.demon.co.uk/







Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.