: select a range of elements from a nested list
- To: mathgroup at smc.vnet.net
- Subject: [mg5459] : [mg5387] select a range of elements from a nested list
- From: Allan Hayes <hay at haystack.demon.co.uk>
- Date: Sat, 7 Dec 1996 00:26:37 -0500
- Sender: owner-wri-mathgroup at wolfram.com
Oliver Schurr <schurro at 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.00347346, 0.651138}, {0.00705477, 0.599932},
{0.00617553, 0.827159}, {0.00227771, 0.373836},
{0.00679162, 0.128556}, {0.0051724, 0.947127},
}
Cases[lst, {x_,y_}/;x<0.1]//Timing
{0.00347346, 0.651138}, {0.00705477, 0.599932},
{0.00617553, 0.827159}, {0.00227771, 0.373836},
{0.00679162, 0.128556}, {0.0051724, 0.947127},
}
Allan Hayes
hay at haystack.demon.co.uk
http://www.haystack.demon.co.uk/