Re: Position function
- To: mathgroup at smc.vnet.net
- Subject: [mg55560] Re: [mg55549] Position function
- From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
- Date: Wed, 30 Mar 2005 03:20:55 -0500 (EST)
- References: <200503290842.DAA07267@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
On 29 Mar 2005, at 10:42, konstantpi at mail15.com wrote: > suppose i have a List: > a={{1,3,1,2,1},{5,6,1,1,3,1}} > how i could know the positions of "1" in every sublist , i could use > Position[a > [[1]],1] and Position[a[[2]],1] > but i want a one formula to give me {{1,3,5},{3,4,6}} For example: In[2]:= a = {{1, 3, 1, 2, 1}, {5, 6, 1, 1, 3, 1}}; In[3]:= Split[Position[a, 1], #1[[1]] == #2[[1]] & ] /. (l_)?VectorQ :> Last[l] Out[3]= {{1, 3, 5}, {3, 4, 6}} > > the second question: > using Position[a,1] will give: > {{1, 1}, {1, 3}, {1, 5}, {2, 3}, {2, 4}, {2, 6}} > in general how to extract only the second item from every sublist so > the output > will be; > {1,3,5,3,4,6} In[4]:= Position[a, 1] /. (l_)?VectorQ :> Last[l] Out[4]= {1,3,5,3,4,6} Andrzej Kozlowski Chiba, Japan http://www.akikoz.net/andrzej/index.html http://www.mimuw.edu.pl/~akoz/
- References:
- Position function
- From: konstantpi@mail15.com
- Position function