Re: [Numpy-discussion] Selecting columns of a matrix

2006-06-22 Thread Pau Gargallo
''' The following mail is a bit long and tedious to read, sorry about that. Here is the abstract: "I would like boolean indexing to work like slices and not like arrays of indices" ''' hi, I'm _really_ sorry to insist, but I have been thinking on it and I don't feel like replacing with nonze

Re: [Numpy-discussion] Selecting columns of a matrix

2006-06-21 Thread Travis Oliphant
Simon Burton wrote: > On Wed, 21 Jun 2006 10:50:26 -0600 > Travis Oliphant <[EMAIL PROTECTED]> wrote: > > >> So, in SVN NumPy, you will be able to do >> >> a[:,V>0] >> a[V>0,:] >> >> The V>0 will be replaced with integer arrays as if nonzero(V>0) had been >> called. >> > > OK. > But just

Re: [Numpy-discussion] Selecting columns of a matrix

2006-06-21 Thread Bill Baxter
On 6/22/06, Alan G Isaac <[EMAIL PROTECTED]> wrote: > Alan G Isaac wrote:>> M.transpose()[V>0]>> If you want the columns as columns,>> you can transpose again.On Wed, 21 Jun 2006, Keith Goodman apparently wrote:> I can't get that to work when M is a n by m matrix: The problem is not M being a matri

Re: [Numpy-discussion] Selecting columns of a matrix

2006-06-21 Thread Simon Burton
On Wed, 21 Jun 2006 10:50:26 -0600 Travis Oliphant <[EMAIL PROTECTED]> wrote: > > So, in SVN NumPy, you will be able to do > > a[:,V>0] > a[V>0,:] > > The V>0 will be replaced with integer arrays as if nonzero(V>0) had been > called. OK. But just for the record, we should note how to do the

Re: [Numpy-discussion] Selecting columns of a matrix

2006-06-21 Thread Alan G Isaac
> Alan G Isaac wrote: >> M.transpose()[V>0] >> If you want the columns as columns, >> you can transpose again. On Wed, 21 Jun 2006, Keith Goodman apparently wrote: > I can't get that to work when M is a n by m matrix: The problem is not M being a matrix. You made V a matrix (i.e., 2d). So

Re: [Numpy-discussion] Selecting columns of a matrix

2006-06-21 Thread Pau Gargallo
On 6/21/06, Travis Oliphant <[EMAIL PROTECTED]> wrote: > Pau Gargallo wrote: > > On 6/21/06, Travis Oliphant <[EMAIL PROTECTED]> wrote: > > > >> Johannes Loehnert wrote: > >> > >>> Hi, > >>> > >>> > >>> > I'm not sure why bool arrays cannot be used as indices. > The "natural" solution to

Re: [Numpy-discussion] Selecting columns of a matrix

2006-06-21 Thread Travis Oliphant
Pau Gargallo wrote: > On 6/21/06, Travis Oliphant <[EMAIL PROTECTED]> wrote: > >> Johannes Loehnert wrote: >> >>> Hi, >>> >>> >>> I'm not sure why bool arrays cannot be used as indices. The "natural" solution to the original problem seemed to be: M[:,V>0] but this

Re: [Numpy-discussion] Selecting columns of a matrix

2006-06-21 Thread Pau Gargallo
On 6/21/06, Travis Oliphant <[EMAIL PROTECTED]> wrote: > Johannes Loehnert wrote: > > Hi, > > > > > >> I'm not sure why bool arrays cannot be used as indices. > >> The "natural" solution to the original problem seemed to be: > >> M[:,V>0] > >> but this is not allowed. > >> > > > > I started a threa

Re: [Numpy-discussion] Selecting columns of a matrix

2006-06-21 Thread Travis Oliphant
Johannes Loehnert wrote: > Hi, > > >> I'm not sure why bool arrays cannot be used as indices. >> The "natural" solution to the original problem seemed to be: >> M[:,V>0] >> but this is not allowed. >> > > I started a thread on this earlier this year. Try searching the archive for > "boolea

Re: [Numpy-discussion] Selecting columns of a matrix

2006-06-21 Thread Travis Oliphant
Bill Baxter wrote: > On 6/21/06, *Simon Burton* <[EMAIL PROTECTED] > > wrote: > > On Wed, 21 Jun 2006 13:48:48 +0900 > "Bill Baxter" <[EMAIL PROTECTED] > wrote: > > > > > >>> a[:,num.where(v>0.5)[0]] > > array([[1, 2, 4], >

Re: [Numpy-discussion] Selecting columns of a matrix

2006-06-21 Thread Keith Goodman
Alan G Isaac wrote: > M.transpose()[V>0] > If you want the columns as columns, > you can transpose again. I can't get that to work when M is a n by m matrix: >> M = asmatrix(rand(3,4)) >> M matrix([[ 0.78970407, 0.78681448, 0.79167808, 0.57857822], [ 0.44567836, 0.23985597, 0.49392

Re: [Numpy-discussion] Selecting columns of a matrix

2006-06-21 Thread Keith Goodman
On 6/20/06, Bill Baxter <[EMAIL PROTECTED]> wrote: > >>> a[:,num.where(v>0.5)[0]] > array([[1, 2, 4], >[6, 7, 9]]) > > I'll put that up on the Matlab->Numpy page. That's a great addition to the Matlab to Numpy page. But it only works if v is a column vector. If v is a row vector, then wh

Re: [Numpy-discussion] Selecting columns of a matrix

2006-06-21 Thread Johannes Loehnert
Hi, > I'm not sure why bool arrays cannot be used as indices. > The "natural" solution to the original problem seemed to be: > M[:,V>0] > but this is not allowed. I started a thread on this earlier this year. Try searching the archive for "boolean indexing" (if it comes back online somewhen). T

Re: [Numpy-discussion] Selecting columns of a matrix

2006-06-21 Thread Alan G Isaac
On Wed, 21 Jun 2006, Bill Baxter apparently wrote: > ew to numpy.nonzero I agree that having the method and function behave so differently is awkward; this was discussed before on this list. It does allow Simon's nicer solution, however. I'm not sure why bool arrays cannot be used as indices

Re: [Numpy-discussion] Selecting columns of a matrix

2006-06-21 Thread Alan G Isaac
On Tue, 20 Jun 2006, Keith Goodman apparently wrote: > I have a matrix M and a vector (n by 1 matrix) V. I want to form a new > matrix that contains the columns of M for which V > 0. > One way to do that in Octave is M(:, find(V > 0)). How is it done in numpy? M.transpose()[V>0] If you want th

Re: [Numpy-discussion] Selecting columns of a matrix

2006-06-21 Thread Bill Baxter
On 6/21/06, Simon Burton <[EMAIL PROTECTED]> wrote: On Wed, 21 Jun 2006 13:48:48 +0900"Bill Baxter" <[EMAIL PROTECTED]> wrote:>> >>> a[:,num.where(v>0.5)[0]]> array([[1, 2, 4], >[6, 7, 9]])>> I'll put that up on the Matlab->Numpy page.oh, yuck. What about this:>>> a[:,num.nonzero(v>0.5)]arr

Re: [Numpy-discussion] Selecting columns of a matrix

2006-06-20 Thread Bill Baxter
On 6/21/06, Erin Sheldon <[EMAIL PROTECTED]> wrote: On 6/20/06, Bill Baxter <[EMAIL PROTECTED]> wrote:> I think that one's on the NumPy for Matlab users, no?>> http://www.scipy.org/NumPy_for_Matlab_Users>> >>> import numpy as num>  >>> a = num.arange (10).reshape(2,5)> >>> a> array([[0, 1, 2, 3, 4

Re: [Numpy-discussion] Selecting columns of a matrix

2006-06-20 Thread Simon Burton
On Wed, 21 Jun 2006 13:48:48 +0900 "Bill Baxter" <[EMAIL PROTECTED]> wrote: > > >>> a[:,num.where(v>0.5)[0]] > array([[1, 2, 4], >[6, 7, 9]]) > > I'll put that up on the Matlab->Numpy page. oh, yuck. What about this: >>> a[:,num.nonzero(v>0.5)] array([[0, 1, 3], [5, 6, 8]]) >>>

Re: [Numpy-discussion] Selecting columns of a matrix

2006-06-20 Thread Erin Sheldon
On 6/20/06, Bill Baxter <[EMAIL PROTECTED]> wrote: > I think that one's on the NumPy for Matlab users, no? > > http://www.scipy.org/NumPy_for_Matlab_Users > > >>> import numpy as num > >>> a = num.arange (10).reshape(2,5) > >>> a > array([[0, 1, 2, 3, 4], >[5, 6, 7, 8, 9]]) > >>> v = num.r

Re: [Numpy-discussion] Selecting columns of a matrix

2006-06-20 Thread Keith Goodman
On 6/20/06, Bill Baxter <[EMAIL PROTECTED]> wrote: > I think that one's on the NumPy for Matlab users, no? > > http://www.scipy.org/NumPy_for_Matlab_Users > > >>> import numpy as num > >>> a = num.arange (10).reshape(2,5) > >>> a > array([[0, 1, 2, 3, 4], >[5, 6, 7, 8, 9]]) > >>> v = num.r

Re: [Numpy-discussion] Selecting columns of a matrix

2006-06-20 Thread Bill Baxter
I think that one's on the NumPy for Matlab users, no? http://www.scipy.org/NumPy_for_Matlab_Users>>> import numpy as num >>> a = num.arange (10).reshape(2,5)>>> aarray([[0, 1, 2, 3, 4],   [5, 6, 7, 8, 9]])>>> v = num.rand(5)>>> varray([ 0.10934855,  0.55719644,  0.7044047 ,  0.19250088,  0.9463

[Numpy-discussion] Selecting columns of a matrix

2006-06-20 Thread Keith Goodman
I have a matrix M and a vector (n by 1 matrix) V. I want to form a new matrix that contains the columns of M for which V > 0. One way to do that in Octave is M(:, find(V > 0)). How is it done in numpy? ___ Numpy-discussion mailing list Numpy-discussion