[Date Index]
[Thread Index]
[Author Index]
Intersection question
*To*: mathgroup at smc.vnet.net
*Subject*: [mg75172] Intersection question
*From*: János <janos.lobb at yale.edu>
*Date*: Thu, 19 Apr 2007 04:33:35 -0400 (EDT)
Hi,
I have a nested list with 250 elements, where the elements of the
list are also nested lists - down 4th deep. The first element in the
list has 249 elements, the second element has 248 elements, etc...
Here is how the 246, 247, 248, 249 and 250 elements of the list are
for illustration:
In[116]:=
vch[[246]]
Out[116]=
{{{}, {}, {}, {{120}},
{{22}, {71}, {113}, {179},
{182}, {250}, {286},
{359}, {439}, {448},
{451}, {455}},
{{35}, {46}, {51}, {63},
{75}, {83}, {88}, {92},
{95}, {96}, {101}, {119},
{131}, {141}, {143},
{152}, {168}, {184},
{204}, {217}, {247},
{258}, {259}, {274},
{275}, {291}, {294},
{295}, {302}, {318},
{327}, {342}, {344},
{346}, {365}, {367},
{369}, {378}, {391},
{405}, {420}, {423},
{430}, {438}, {442}},
{{16}, {18}, {19}, {24},
{26}, {44}, {84}, {85},
{144}, {188}, {191},
{205}, {216}, {221},
{238}, {251}, {260},
{264}, {292}, {332},
{336}, {339}, {348},
{352}, {376}, {379},
{392}, {398}, {404},
{411}, {412}, {419}},
{{45}, {268}, {446}}, {},
{}, {}}, {{}, {}, {}, {},
{}, {}, {}, {}, {}, {},
{}}, {{}, {}, {}, {}, {},
{}, {}, {}, {}, {}, {}},
{{}, {}, {}, {}, {}, {},
{}, {}, {}, {}, {}}}
In[121]:=
vch[[247]]
Out[121]=
{{{}, {}, {}, {}, {}, {}, {},
{}, {}, {}, {}},
{{}, {}, {}, {}, {}, {},
{}, {}, {}, {}, {}},
{{}, {}, {}, {}, {}, {},
{}, {}, {}, {}, {}}}
In[56]:=
vch[[248]]
Out[56]=
{{{}, {}, {}, {}, {}, {}, {},
{}, {}, {{130}}, {{263}},
{{233}}, {}, {}, {},
{{198}}, {}, {}, {}, {}},
{{}, {}, {}, {}, {}, {},
{}, {}, {}, {}, {}, {},
{}, {}, {}, {}, {}, {},
{}}}
In[61]:=
vch[[249]]
Out[61]=
{{{}, {}, {}, {}, {{87}},
{{11}, {58}, {242}},
{{5}, {22}, {77}, {81},
{107}, {116}, {167},
{182}, {196}, {227},
{275}, {335}, {367},
{394}}, {{28}, {45},
{68}, {126}, {129},
{145}, {175}, {185},
{213}, {218}, {245},
{294}, {329}, {336},
{352}, {407}, {458}},
{{2}, {48}, {85}, {189},
{200}, {282}, {300},
{345}, {357}}, {{293}},
{{60}}, {{6}, {101}},
{{429}}, {{296}}, {{302}},
{}, {}, {}, {}}}
In[66]:=
vch[[250]]
Out[66]=
{}
The "numbers" shown in the outputs above are identifiers or name tags.
To find out where let say ID=1 occurs in the vch list, I do the
following:
In[79]:=
Position[vch, {1}]
Out[79]=
{{3, 1, 9, 1}, {5, 1, 10, 1},
{10, 1, 10, 1}, {15, 1, 9,
1}, {25, 1, 7, 1},
{29, 1, 9, 1}, {61, 1, 9,
1}, {70, 1, 10, 1},
{79, 1, 10, 1}, {81, 1, 12,
1}, {86, 1, 13, 1},
{90, 1, 9, 1}, {129, 1, 9,
1}, {143, 1, 8, 1},
{147, 1, 11, 1},
{164, 1, 13, 1},
{169, 1, 11, 1},
{182, 1, 10, 1},
{186, 1, 14, 1},
{221, 1, 14, 1},
{227, 1, 12, 1},
{232, 1, 9, 1}}
To find out where let say ID=2 occurs in the vch list I do the
following:
In[88]:=
Position[vch, {2}]
Out[88]=
{{6, 1, 9, 1}, {6, 2, 9, 1},
{7, 1, 9, 1}, {21, 1, 8,
1}, {27, 1, 7, 1},
{29, 1, 11, 1}, {31, 1, 12,
1}, {42, 1, 13, 1},
{42, 2, 13, 1}, {43, 1, 13,
1}, {61, 1, 12, 1},
{68, 1, 10, 1}, {82, 1, 10,
1}, {93, 1, 13, 1},
{95, 1, 15, 1},
{113, 1, 13, 1},
{123, 1, 10, 1},
{136, 1, 12, 1},
{139, 1, 11, 1},
{141, 1, 13, 1},
{174, 1, 13, 1},
{188, 1, 8, 1},
{198, 1, 10, 1},
{203, 1, 10, 1},
{219, 1, 9, 1},
{230, 1, 15, 1},
{249, 1, 9, 1}}
If I am just interested in not in the exact occurrence like {6, 1, 9, =
1}, but just in the first element of this result - the 6 -, I do the =
following for IDs 1 and 2:
In[93]:=
First /@ Position[vch, {1}]
Out[93]=
{3, 5, 10, 15, 25, 29, 61,
70, 79, 81, 86, 90, 129,
143, 147, 164, 169, 182,
186, 221, 227, 232}
In[94]:=
First /@ Position[vch, {2}]
Out[94]=
{6, 6, 7, 21, 27, 29, 31, 42,
42, 43, 61, 68, 82, 93, 95,
113, 123, 136, 139, 141,
174, 188, 198, 203, 219,
230, 249}
The Intersection of these two lists would show me those list elements =
in vch where the two IDs can be found together:
In[50]:=
Intersection[First /@
Position[vch, {1}],
First /@ Position[vch, {2}]]
Out[50]=
{29, 61}
Now, I would like to know this result not just for IDs 1 and 2, but
for any pairs of IDS from 1 to 459. For me, being a newbie, the
simplest thing to do is to create a nested table like:
ti = Table[Table[Length[
Intersection[First /@
Position[vch, {i}],
First /@ Position[vch,
{j}]]], {j, 1,
Length[spsplit]}],
{i, 1, Length[spsplit]}];
Length[spsplit] is 459.
On my 2Ghz G5 with two processors this nested table creation takes 2
days. I am wondering if there is another way to get the same result
from vch...... FASTer.
Thanks ahead,
J=E1nos
----------------------------------------------
Trying to argue with a politician is like lifting up the head of a
corpse.
(S. Lem: His Master Voice)
Prev by Date:
** Importing and retaining graphics**
Next by Date:
**Re: neat way to program minimum of sum**
Previous by thread:
**RE: Importing and retaining graphics**
Next by thread:
**Re: how to get the table 2**
| |