Re: indexing lists/arrays question

2010-05-13 Thread Tim Chase
On 05/13/2010 12:51 PM, a wrote: If your two arrays are of the same length, you can do things like a = [2,3,3,4,5,6] b = ['a', 'b', 'c', 'd', 'e', 'f'] print [m for (n,m) in zip(a,b) if n == 3] and skip the indexes altogether. mmm, that's clever, thanks. although i don't know wh

Re: indexing lists/arrays question

2010-05-13 Thread a
On 13 May, 18:18, Tim Chase wrote: > On 05/13/2010 10:45 AM, a wrote: > > > > > > >>> a=[2,3,3,4,5,6] > > >>> i want to know the indices where a==3 (ie 1 and 2) > > >> indexes = [i for (i, v) in enumerate(a) where v==3] > > >>> then i want to reference these in a > > >> In a _what_?  You can then

Re: indexing lists/arrays question

2010-05-13 Thread a
On 13 May, 17:41, Carey Tilden wrote: > On Thu, May 13, 2010 at 8:45 AM, a > wrote: > > On 13 May, 16:19, Tim Chase wrote: > >> On 05/13/2010 09:36 AM, a wrote: > > >> > this must be easy but its taken me a couple of hours already > > >> > i have > > >> > a=[2,3,3,4,5,6] > > >> > i want to know

Re: indexing lists/arrays question

2010-05-13 Thread Tim Chase
On 05/13/2010 10:45 AM, a wrote: a=[2,3,3,4,5,6] i want to know the indices where a==3 (ie 1 and 2) indexes = [i for (i, v) in enumerate(a) where v==3] then i want to reference these in a In a _what_? You can then do things like for i in indexes: print a[i] (but you already

Re: indexing lists/arrays question

2010-05-13 Thread Carey Tilden
On Thu, May 13, 2010 at 8:45 AM, a wrote: > On 13 May, 16:19, Tim Chase wrote: >> On 05/13/2010 09:36 AM, a wrote: >> >> > this must be easy but its taken me a couple of hours already >> >> > i have >> >> > a=[2,3,3,4,5,6] >> >> > i want to know the indices where a==3 (ie 1 and 2) >> >> indexes =

Re: indexing lists/arrays question

2010-05-13 Thread a
On 13 May, 16:19, Tim Chase wrote: > On 05/13/2010 09:36 AM, a wrote: > > > this must be easy but its taken me a couple of hours already > > > i have > > > a=[2,3,3,4,5,6] > > > i want to know the indices where a==3 (ie 1 and 2) > > indexes = [i for (i, v) in enumerate(a) where v==3] > > > then i

Re: indexing lists/arrays question

2010-05-13 Thread a
On 13 May, 15:47, Stefan Behnel wrote: > a, 13.05.2010 16:36: > > > this must be easy but its taken me a couple of hours already > > > i have > > > a=[2,3,3,4,5,6] > > > i want to know the indices where a==3 (ie 1 and 2) > >    indices = [ i for i,item in enumerate(a) if item == 3 ] > > > then i w

Re: indexing lists/arrays question

2010-05-13 Thread Tim Chase
On 05/13/2010 09:36 AM, a wrote: this must be easy but its taken me a couple of hours already i have a=[2,3,3,4,5,6] i want to know the indices where a==3 (ie 1 and 2) indexes = [i for (i, v) in enumerate(a) where v==3] then i want to reference these in a In a _what_? You can then do th

Re: indexing lists/arrays question

2010-05-13 Thread Neil Cerutti
On 2010-05-13, Stefan Behnel wrote: > a, 13.05.2010 16:36: >> this must be easy but its taken me a couple of hours already >> >> i have >> >> a=[2,3,3,4,5,6] >> >> i want to know the indices where a==3 (ie 1 and 2) > >indices = [ i for i,item in enumerate(a) if item == 3 ] That form of list c

Re: indexing lists/arrays question

2010-05-13 Thread Neil Cerutti
On 2010-05-13, a wrote: > this must be easy but its taken me a couple of hours already > > i have > > a=[2,3,3,4,5,6] > > i want to know the indices where a==3 (ie 1 and 2) > > then i want to reference these in a > > ie what i would do in IDL is > > b=where(a eq 3) > a1=a(b) > > any ideas? For a

Re: indexing lists/arrays question

2010-05-13 Thread Matthew Wilson
On Thu 13 May 2010 10:36:58 AM EDT, a wrote: > this must be easy but its taken me a couple of hours already > > i have > > a=[2,3,3,4,5,6] > > i want to know the indices where a==3 (ie 1 and 2) > > then i want to reference these in a > > ie what i would do in IDL is > > b=where(a eq 3) > a1=a(b)

Re: indexing lists/arrays question

2010-05-13 Thread Stefan Behnel
a, 13.05.2010 16:36: this must be easy but its taken me a couple of hours already i have a=[2,3,3,4,5,6] i want to know the indices where a==3 (ie 1 and 2) indices = [ i for i,item in enumerate(a) if item == 3 ] then i want to reference these in a print [ a[i] for i in indices ] St

indexing lists/arrays question

2010-05-13 Thread a
this must be easy but its taken me a couple of hours already i have a=[2,3,3,4,5,6] i want to know the indices where a==3 (ie 1 and 2) then i want to reference these in a ie what i would do in IDL is b=where(a eq 3) a1=a(b) any ideas? Thanks -- http://mail.python.org/mailman/listinfo/pyth