Re: [Numpy-discussion] Selected and altering a submatrix

2007-01-30 Thread Steve Lianoglou
Hi all, Thank you for your replies ... my question was initially unclear in that I knew that using normal slicing would do the trick, but it was rather a list of indices that couldn't be represented as a slice that was bugging me. Luckily, Robert's solution solves this problem for the gene

Re: [Numpy-discussion] Selected and altering a submatrix

2007-01-29 Thread Robert Kern
Steve Lianoglou wrote: > === > import numpy as N > mat = N.zeros((10,10)) > rows = [0,1,2] > cols = [4,5,6] > > for row in rows: > mat[row,cols] += 1 > > > > I found something on the lists from a few years back that was in > reference to numeric or numarray that suggested doing some g

Re: [Numpy-discussion] Selected and altering a submatrix

2007-01-29 Thread Keith Goodman
On 1/29/07, Steve Lianoglou <[EMAIL PROTECTED]> wrote: > For example, say I have a 10x10 array and only want to add some > number to the elements in the submatrix that consists of the [0,1,2] > th rows, and [4,5,6]th colums. Here's one way to do it: i,j = N.mgrid[0:3,4:7] mat[i,j] += 1 __

Re: [Numpy-discussion] Selected and altering a submatrix

2007-01-29 Thread Sebastian Haase
How about mat[0:3, 4:7] += 1 -Sebastian On 1/29/07, Steve Lianoglou <[EMAIL PROTECTED]> wrote: > > Hi, > > > > I was just curious what the "correct" (fast) way to select and alter > > a submatrix. > > > > For example, say I have a 10x10 array and only want to add some > > number to the elements

Re: [Numpy-discussion] Selected and altering a submatrix

2007-01-29 Thread Sebastian Haase
How about mat[0:3, 4:7] += 1 -Sebastian On 1/29/07, Steve Lianoglou <[EMAIL PROTECTED]> wrote: > Hi, > > I was just curious what the "correct" (fast) way to select and alter > a submatrix. > > For example, say I have a 10x10 array and only want to add some > number to the elements in the submatr

[Numpy-discussion] Selected and altering a submatrix

2007-01-29 Thread Steve Lianoglou
Hi, I was just curious what the "correct" (fast) way to select and alter a submatrix. For example, say I have a 10x10 array and only want to add some number to the elements in the submatrix that consists of the [0,1,2] th rows, and [4,5,6]th colums. You can imagine that those rows/cols sele