Re: Conditional list indexing
- To: mathgroup at smc.vnet.net
- Subject: [mg95919] Re: Conditional list indexing
- From: Bill Rowe <readnews at sbcglobal.net>
- Date: Thu, 29 Jan 2009 06:00:45 -0500 (EST)
On 1/28/09 at 6:43 AM, danielelinaro at gmail.com (daniele) wrote:
>Hello everybody, I'd like to know how I can get the indices of the
>elements in a list that satisfy a certain condition. Here's an
>example: suppose I have the list
>a = Table[Prime[i],{i,10}];
>
>that contains {2,3,5,7,11,13,17,19,23,29}.
>If I execute the command
>b = Select[a,#>15&];
>b will contain {17,19,23,29}. I'd like to find a way to obtain a
>third list, say c, that will contain {7,8,9,10}, i.e. the indices of
>the elements in list a that are greater than 15.
Here is one way to do what you want using Pick
In[4]:= Pick[Range@Length@a, Sign[a - 15], 1]
Out[4]= {7,8,9,10}