Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2005
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Position function

  • To: mathgroup at smc.vnet.net
  • Subject: [mg55579] Re: [mg55549] Position function
  • From: DrBob <drbob at bigfoot.com>
  • Date: Wed, 30 Mar 2005 03:21:16 -0500 (EST)
  • References: <200503290842.DAA07267@smc.vnet.net>
  • Reply-to: drbob at bigfoot.com
  • Sender: owner-wri-mathgroup at wolfram.com

a = {{1, 3, 1, 2, 1}, {5, 6, 1, 1, 3, 1}}
Position[a, 1]
Split[%, #1[[1]] == #2[[1]] &]
Last /@ Transpose /@ %

{{1,3,1,2,1},{5,6,1,1,3,1}}
{{1,1},{1,3},{1,5},{2,3},{2,4},{2,6}}
{{{1,1},{1,3},{1,5}},{{2,3},{2,4},{2,6}}}
{{1,3,5},{3,4,6}}

Position[a,1][[All,2]]

{1,3,5,3,4,6}

Bobby

On Tue, 29 Mar 2005 03:42:32 -0500 (EST), <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}}
>
> 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}
> thanks
> konst.
>
>
>
>



-- 
DrBob at bigfoot.com


  • Prev by Date: Re: Mathematica max, min
  • Next by Date: Re: Position function
  • Previous by thread: Position function
  • Next by thread: Re: Position function