MathGroup Archive 2011

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

Search the Archive

Re: how to apply Position repeatedly without a loop?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg118652] Re: how to apply Position repeatedly without a loop?
  • From: DrMajorBob <btreat1 at austin.rr.com>
  • Date: Fri, 6 May 2011 07:22:01 -0400 (EDT)

a = {{1, 2, 3}, {3, 4, 5}, {6, 7, 8}};
elements = {3, 6};
Position[a, Alternatives @@ elements]

{{1, 3}, {2, 1}, {3, 1}}

Bobby

On Thu, 05 May 2011 04:24:01 -0500, steveh44 <steve_h44 at yahoo.com> wrote:

> i have matrix A and wanted to find the Positions in this matrix of
> some elements which listed in some another vector.
>
> how to use Position to do it without a loop?
>
> I tried this:
>
> In[192]:= A={{1,2,3},
> {3,4,5},
> {6,7,8}};
> elements={3,6};
>
> Position[A,r[[1]]]
> Out[194]= {{1,1}}
>
> Position[A,r[[2]]]
> Out[197]= {{1,2}}
>
> but I want to do something like
>
> Position[A,r]
> but this does not work.
>
> I tried Map, Thread, etc.. but could not get it to work. not sure what
> the syntax is.
>
> thanks for help
> steve
>
>
>


-- 
DrMajorBob at yahoo.com


  • Prev by Date: Converting a list to arguments for a function --- How?
  • Next by Date: Re: How to define FrontEndEventActions for keyboard combinations with Shift and Alt?
  • Previous by thread: how to apply Position repeatedly without a loop?
  • Next by thread: Re: how to apply Position repeatedly without a loop?