Re: How to return the position of a multidimensional list ..

• To: mathgroup at smc.vnet.net
• Subject: [mg7065] Re: [mg7040] How to return the position of a multidimensional list ..
• From: "w.meeussen" <w.meeussen.vdmcc at vandemoortele.be>
• Date: Sat, 3 May 1997 22:04:56 -0400 (EDT)
• Sender: owner-wri-mathgroup at wolfram.com

```At 21:31 2-05-97 -0400, Chung Cheong Ming wrote:
>I have a list of lists (multidimensional array), if for each sublist, I
>know the first 2 elements, how to I know the position where this sublist
>situates in the list?
>
>eg.  OuterList = {sublist1, sublist2, ...}
>
>I want to find where a sublist situates in the OuterList if I know the
>first 2 elements of this sublist.
>
>Joseph
>

hi,

does "Position[outerlist,{a,b,__}]" help?
********************************************************************************
Example 1:

In[38]:=it=Outer[List,{a,b},{a,b},{a,b},{a,b}]

Out[38]=
{{{{{a,a,a,a},{a,a,a,b}},{{a,a,b,a},{a,a,b,b}}},{{{a,b,a,a},{a,b,a,b}},{{a,b,
b,a},{a,b,b,b}}}},{{{{b,a,a,a},{b,a,a,b}},{{b,a,b,a},{b,a,b,b}}},{{{
b,b,a,a},{b,b,a,b}},{{b,b,b,a},{b,b,b,b}}}}}

In[39]:=pos=Position[it,{a,b,__}]
Out[39]={{1,2,1,1},{1,2,1,2},{1,2,2,1},{1,2,2,2}}

In[40]:=Extract[it,pos]
Out[40]={{a,b,a,a},{a,b,a,b},{a,b,b,a},{a,b,b,b}}

********************************************************************************
Example 2:

In[46]:=it=Flatten[Outer[dummy,{a,b},{a,b},{a,b},{a,b}]] /.dummy->List
Out[46]=
{{a,a,a,a},{a,a,a,b},{a,a,b,a},{a,a,b,b},{a,b,a,a},{a,b,a,b},{a,b,b,a},{a,b,b,
b},{b,a,a,a},{b,a,a,b},{b,a,b,a},{b,a,b,b},{b,b,a,a},{b,b,a,b},{b,b,b,a},{
b,b,b,b}}

In[47]:=pos=Position[it,{a,b,__}]
Out[47]={{5},{6},{7},{8}}
In[48]:=Extract[it,pos]
Out[48]={{a,b,a,a},{a,b,a,b},{a,b,b,a},{a,b,b,b}}
********************************************************************************

Dr. Wouter L. J. MEEUSSEN
eu000949 at pophost.eunet.be
w.meeussen.vdmcc at vandemoortele.be

```

• Prev by Date: Re: (Q:) ReplacePart + SubMatrix replacement
• Next by Date: Re: Limits & predicates with options.
• Previous by thread: backets for non-american keybords, 2.2.3
• Next by thread: Re: Is a solution possible to this exponential equation?