Re: With Nearest
- To: mathgroup at smc.vnet.net
- Subject: [mg121105] Re: With Nearest
- From: Peter Pein <petsie at dordos.net>
- Date: Sun, 28 Aug 2011 04:06:01 -0400 (EDT)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- References: <j3anc3$hdo$1@smc.vnet.net>
Am 27.08.2011 14:19, schrieb graser:
> Dear Mathematica group,
> I have a simple question for you.
> Let's say there is an array or matrix like
>
> AA = {{1.3, 1.5}, {21.5, 23.6}, {10, 19}};
>
> If I want to extract a list whose second element is close to 20, How
> can I do it with Nearest function?
> Or is there any other method possible?
> ( In this case, the answer should be {10, 19} )
>
> Thanks!
>
>
Hi,
using Nearest, the following seems to be the fastest which comes to my mind:
In[4]:= SeedRandom[123];
AA = 0.125*RandomInteger[320, {10^5, 2}];
Timing[Length[ne =
Parallelize[Cases[AA,
{_, Alternatives @@ Nearest[AA[[All,2]], 20]}, 1]]
]]
Out[6]= {1.779,298}
Peter