Search All of the Math Forum:

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

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

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

 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

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/