Re: [Numpy-discussion] indexing question

2010-11-22 Thread John Salvatier
I think that the only speedup you will get is defining an index only once and reusing it. 2010/11/22 Ernest Adrogué : > 22/11/10 @ 14:04 (-0600), thus spake Robert Kern: >> > This way, I get the elements (0,1) and (1,1) which is what >> > I wanted. The question is: is it possible to omit the [0,1]

Re: [Numpy-discussion] indexing question

2010-11-22 Thread Ernest Adrogué
22/11/10 @ 14:04 (-0600), thus spake Robert Kern: > > This way, I get the elements (0,1) and (1,1) which is what > > I wanted. The question is: is it possible to omit the [0,1] > > in the index? > > No, but you can write generic code for it: > > t[np.arange(t.shape[0]), x, y] Thank you. This i

Re: [Numpy-discussion] indexing question

2010-11-22 Thread Ernest Adrogué
22/11/10 @ 11:20 (-0800), thus spake John Salvatier: > I didn't realize the x's and y's were varying the first time around. > There's probably a way to omit it, but I think the conceptually > simplest way is probably what you had to begin with. Build an index by > saying i = numpy.arange(0, t.shape

Re: [Numpy-discussion] indexing question

2010-11-22 Thread Robert Kern
2010/11/21 Ernest Adrogué : > Hi, > > Suppose an array of shape (N,2,2), that is N arrays of > shape (2,2). I want to select an element (x,y) from each one > of the subarrays, so I get a 1-dimensional array of length > N. For instance: > > In [228]: t=np.arange(8).reshape(2,2,2) > > In [229]: t > O

Re: [Numpy-discussion] indexing question

2010-11-22 Thread Ernest Adrogué
22/11/10 @ 11:08 (-0800), thus spake Christopher Barker: > On 11/21/10 11:37 AM, Ernest Adrogué wrote: > >>so you want > >> > >>t[:,x,y] > > > >I tried that, but it's not the same: > > > >In [307]: t[[0,1],x,y] > >Out[307]: array([1, 7]) > > > >In [308]: t[:,x,y] > >Out[308]: > >array([[1, 3], > >

Re: [Numpy-discussion] indexing question

2010-11-22 Thread John Salvatier
I didn't realize the x's and y's were varying the first time around. There's probably a way to omit it, but I think the conceptually simplest way is probably what you had to begin with. Build an index by saying i = numpy.arange(0, t.shape[0]) then you can do t[i, x,y] On Mon, Nov 22, 2010 at 11:0

Re: [Numpy-discussion] indexing question

2010-11-22 Thread Christopher Barker
On 11/21/10 11:37 AM, Ernest Adrogué wrote: >> so you want >> >> t[:,x,y] > > I tried that, but it's not the same: > > In [307]: t[[0,1],x,y] > Out[307]: array([1, 7]) > > In [308]: t[:,x,y] > Out[308]: > array([[1, 3], > [5, 7]]) what is your t? Here's my example, which I think matches wh

Re: [Numpy-discussion] indexing question

2010-11-21 Thread Ernest Adrogué
Hi, 21/11/10 @ 11:28 (-0800), thus spake John Salvatier: > yes use the symbol ':' > > so you want > > t[:,x,y] I tried that, but it's not the same: In [307]: t[[0,1],x,y] Out[307]: array([1, 7]) In [308]: t[:,x,y] Out[308]: array([[1, 3], [5, 7]]) No? -- Ernest

Re: [Numpy-discussion] indexing question

2010-11-21 Thread John Salvatier
yes use the symbol ':' so you want t[:,x,y] 2010/11/21 Ernest Adrogué : > Hi, > > Suppose an array of shape (N,2,2), that is N arrays of > shape (2,2). I want to select an element (x,y) from each one > of the subarrays, so I get a 1-dimensional array of length > N. For instance: > > In [228]: t=

Re: [Numpy-discussion] indexing question

2010-11-21 Thread John Salvatier
read about basic slicing : http://docs.scipy.org/doc/numpy/reference/arrays.indexing.html On Sun, Nov 21, 2010 at 11:28 AM, John Salvatier wrote: > yes use the symbol ':' > > so you want > > t[:,x,y] > > 2010/11/21 Ernest Adrogué : >> Hi, >> >> Suppose an array of shape (N,2,2), that is N arrays

[Numpy-discussion] indexing question

2010-11-21 Thread Ernest Adrogué
Hi, Suppose an array of shape (N,2,2), that is N arrays of shape (2,2). I want to select an element (x,y) from each one of the subarrays, so I get a 1-dimensional array of length N. For instance: In [228]: t=np.arange(8).reshape(2,2,2) In [229]: t Out[229]: array([[[0, 1], [2, 3]],

Re: [Numpy-discussion] indexing question

2010-06-21 Thread Wes McKinney
On Mon, Jun 21, 2010 at 7:10 PM, Robert Kern wrote: > On Mon, Jun 21, 2010 at 17:42, Neal Becker wrote: >> Robert Kern wrote: >> >>> On Mon, Jun 21, 2010 at 14:01, Neal Becker wrote: Can I find an efficient way to do this? I have a 2d array, A, 80 rows by 880 columns. I

Re: [Numpy-discussion] indexing question

2010-06-21 Thread Robert Kern
On Mon, Jun 21, 2010 at 17:42, Neal Becker wrote: > Robert Kern wrote: > >> On Mon, Jun 21, 2010 at 14:01, Neal Becker wrote: >>> Can I find an efficient way to do this? >>> >>> I have a 2d array, A, 80 rows by 880 columns. >>> >>> I have a vector, B, of length 80, with scalar indexes. >> >> I as

Re: [Numpy-discussion] indexing question

2010-06-21 Thread Neal Becker
Robert Kern wrote: > On Mon, Jun 21, 2010 at 14:01, Neal Becker wrote: >> Can I find an efficient way to do this? >> >> I have a 2d array, A, 80 rows by 880 columns. >> >> I have a vector, B, of length 80, with scalar indexes. > > I assume you mean 880. > >> I want a vector output C where >> C[

Re: [Numpy-discussion] indexing question

2010-06-21 Thread Robert Kern
On Mon, Jun 21, 2010 at 14:01, Neal Becker wrote: > Can I find an efficient way to do this? > > I have a 2d array, A, 80 rows by 880 columns. > > I have a vector, B, of length 80, with scalar indexes. I assume you mean 880. > I want a vector output C where > C[i] = A[b[i],i] (i=0,879) C = A[b,

[Numpy-discussion] indexing question

2010-06-21 Thread Neal Becker
Can I find an efficient way to do this? I have a 2d array, A, 80 rows by 880 columns. I have a vector, B, of length 80, with scalar indexes. I want a vector output C where C[i] = A[b[i],i] (i=0,879) ___ NumPy-Discussion mailing list NumPy-Discussion@s

Re: [Numpy-discussion] indexing question

2010-03-30 Thread josef . pktd
On Tue, Mar 30, 2010 at 10:13 AM, Tom K. wrote: > > This one bit me again, and I am trying to understand it better so I can > anticipate when it will happen. > > What I want to do is get rid of singleton dimensions, and index into the > last dimension with an array. > > In [1]: import numpy as np

Re: [Numpy-discussion] indexing question

2010-03-30 Thread Robert Kern
On Tue, Mar 30, 2010 at 09:46, Charles R Harris wrote: > > > On Tue, Mar 30, 2010 at 8:13 AM, Tom K. wrote: >> >> This one bit me again, and I am trying to understand it better so I can >> anticipate when it will happen. >> >> What I want to do is get rid of singleton dimensions, and index into t

Re: [Numpy-discussion] indexing question

2010-03-30 Thread Charles R Harris
On Tue, Mar 30, 2010 at 8:13 AM, Tom K. wrote: > > This one bit me again, and I am trying to understand it better so I can > anticipate when it will happen. > > What I want to do is get rid of singleton dimensions, and index into the > last dimension with an array. > > In [1]: import numpy as np

Re: [Numpy-discussion] indexing question

2010-03-30 Thread Alan G Isaac
On 3/30/2010 10:13 AM, Tom K. wrote: > What I want to do is get rid of singleton dimensions, and index into the > last dimension with an array. >>> x=np.zeros((10,1,1,1,14,1024)) >>> np.squeeze(x).shape (10, 14, 1024) hth, Alan Isaac ___ NumPy-Discussio

[Numpy-discussion] indexing question

2010-03-30 Thread Tom K.
This one bit me again, and I am trying to understand it better so I can anticipate when it will happen. What I want to do is get rid of singleton dimensions, and index into the last dimension with an array. In [1]: import numpy as np In [2]: x=np.zeros((10,1,1,1,14,1024)) In [3]: x[:,0,0,0,:

Re: [Numpy-discussion] indexing question

2009-12-20 Thread josef . pktd
On Sun, Dec 20, 2009 at 8:58 PM, Alan G Isaac wrote: > Why is s3 F_CONTIGUOUS, and perhaps equivalently, > why is its C_CONTIGUOUS data in s3.base (below)? > Thanks, > Alan Isaac > a3 > array([[ 0,  1,  2,  3,  4,  5], >        [ 6,  7,  8,  9, 10, 11]]) a3.flags >   C_CONTIGUOUS : True

[Numpy-discussion] indexing question

2009-12-20 Thread Alan G Isaac
Why is s3 F_CONTIGUOUS, and perhaps equivalently, why is its C_CONTIGUOUS data in s3.base (below)? Thanks, Alan Isaac >>> a3 array([[ 0, 1, 2, 3, 4, 5], [ 6, 7, 8, 9, 10, 11]]) >>> a3.flags C_CONTIGUOUS : True F_CONTIGUOUS : False OWNDATA : True WRITEABLE : True ALIG

Re: [Numpy-discussion] indexing question

2009-03-05 Thread Robin
On Thu, Mar 5, 2009 at 9:15 PM, Stéfan van der Walt wrote: > Hi Robin > > 2009/3/5 Robin : >> On Thu, Mar 5, 2009 at 10:57 AM, Robin wrote: >>> On Thu, Mar 5, 2009 at 10:40 AM, Robin wrote: Hi, I have an indexing problem, and I know it's a bit lazy to ask the list, sometime w

Re: [Numpy-discussion] indexing question

2009-03-05 Thread Stéfan van der Walt
Hi Robin 2009/3/5 Robin : > On Thu, Mar 5, 2009 at 10:57 AM, Robin wrote: >> On Thu, Mar 5, 2009 at 10:40 AM, Robin wrote: >>> Hi, >>> >>> I have an indexing problem, and I know it's a bit lazy to ask the >>> list, sometime when people do interesting tricks come up so I hope no >>> one minds! >>

Re: [Numpy-discussion] indexing question

2009-03-05 Thread Robin
On Thu, Mar 5, 2009 at 10:57 AM, Robin wrote: > On Thu, Mar 5, 2009 at 10:40 AM, Robin wrote: >> Hi, >> >> I have an indexing problem, and I know it's a bit lazy to ask the >> list, sometime when people do interesting tricks come up so I hope no >> one minds! >> >> I have a 2D array X.shape = (a,

Re: [Numpy-discussion] indexing question

2009-03-05 Thread Robin
On Thu, Mar 5, 2009 at 10:40 AM, Robin wrote: > Hi, > > I have an indexing problem, and I know it's a bit lazy to ask the > list, sometime when people do interesting tricks come up so I hope no > one minds! > > I have a 2D array X.shape = (a,b) > > and I want to change it into new array which is s

Re: [Numpy-discussion] indexing question

2009-03-05 Thread Robin
On Thu, Mar 5, 2009 at 10:40 AM, Robin wrote: > Hi, > > I have an indexing problem, and I know it's a bit lazy to ask the > list, sometime when people do interesting tricks come up so I hope no > one minds! > > I have a 2D array X.shape = (a,b) > > and I want to change it into new array which is s

[Numpy-discussion] indexing question

2009-03-05 Thread Robin
Hi, I have an indexing problem, and I know it's a bit lazy to ask the list, sometime when people do interesting tricks come up so I hope no one minds! I have a 2D array X.shape = (a,b) and I want to change it into new array which is shape (2,(a*b)) which has the following form: [ X[0,0], X[0,1]