Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #11349
| From | Tomas Garza <tgarza10@msn.com> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: Find Position of many elements in a large list. |
| Date | 2012-08-15 07:32 +0000 |
| Message-ID | <k0fjb8$q7a$1@smc.vnet.net> (permalink) |
| References | <20120814082221.E17D66791@smc.vnet.net> |
| Organization | Time-Warner Telecom |
The lists needn't be sorted. Take the following example:
In[10]:= X = Range[1000000]; Y = RandomSample[Range[10000000], 10000];
The positions of X where there is a member of Y are found using
In[16]:= pos = Flatten[Position[X, #] & /@ Intersection[X, Y]]; // Timing
Out[16]= {8.39046, Null}
I don't know if 8.4 seconds is fast enough for your needs. This timing depends very much on the length of the intersection.
-Tomas
> From: benp84@gmail.com
> Subject: Find Position of many elements in a large list.
> To: mathgroup@smc.vnet.net
> Date: Tue, 14 Aug 2012 04:22:21 -0400
>
> I have a sorted, 1-dimensional list X of 1,000,000 integers, and a sorted, 1-dimensional list Y of 10,000 integers. Most, but not all, of the elements of Y are also elements of X. I'd like to know the positions of the elements in X that are also in Y. What's the fastest way to compute this?
>
> I have an algorithm in mind but it requires lots of custom code and I'm wondering if there's a clever way to do it with built-in functions. Thanks.
>
Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread
Re: Find Position of many elements in a large list. Tomas Garza <tgarza10@msn.com> - 2012-08-15 07:32 +0000
csiph-web