Re: [Numpy-discussion] incrementing along a diagonal

2006-10-11 Thread Johannes Loehnert
Hi, I absolutely do not know perl, so I do not know what the expression you posted does. However, the key is just to understand indexing in numpy: if you have a matrix mat and index arrays index1, index2 with, lets say, index1 = array([ 17, 19, 29]) index2 = array([ 12, 3, 9]) then the entri

Re: [Numpy-discussion] incrementing along a diagonal

2006-10-11 Thread Travis Oliphant
David Novakovic wrote: > Hi, > > i'm moving some old perl PDL code to python. I've come across a line > which changes values in a diagonal line accross a matrix. > > matrix.diagonal() returns a list of values, but making changes to these > does not reflect in the original (naturally). > > I'm just

Re: [Numpy-discussion] incrementing along a diagonal

2006-10-11 Thread David Novakovic
Oct 12, 2006 8:58 AM > Subject: Re: [Numpy-discussion] incrementing along a diagonal > To: Discussion of Numerical Python > > > > On 10/12/06, David Novakovic <[EMAIL PROTECTED]> wrote: >> Johannes Loehnert wrote: >> This is very nice, exactly what i want, but it

Re: [Numpy-discussion] incrementing along a diagonal

2006-10-11 Thread Bill Baxter
On 10/12/06, David Novakovic <[EMAIL PROTECTED]> wrote: > Johannes Loehnert wrote: > This is very nice, exactly what i want, but it doesnt work for mxn > matricies: > > >>> x = zeros((5,3)) > >>> x > array([[0, 0, 0], >[0, 0, 0], >[0, 0, 0], >[0, 0, 0], >[0, 0, 0]])

Re: [Numpy-discussion] incrementing along a diagonal

2006-10-11 Thread David Novakovic
Johannes Loehnert wrote: >> I'm just wondering if there is a way that i can increment all the values >> along a diagonal? >> > > Assume you want to change mat. > > # min() only necessary for non-square matrices > index = arange(min(mat.shape[0], mat.shape[1])) > # add 1 to each diagonal elemen

Re: [Numpy-discussion] incrementing along a diagonal

2006-10-11 Thread Johannes Loehnert
> I'm just wondering if there is a way that i can increment all the values > along a diagonal? Assume you want to change mat. # min() only necessary for non-square matrices index = arange(min(mat.shape[0], mat.shape[1])) # add 1 to each diagonal element matrix[index, index] += 1 # add some other

[Numpy-discussion] incrementing along a diagonal

2006-10-11 Thread David Novakovic
Hi, i'm moving some old perl PDL code to python. I've come across a line which changes values in a diagonal line accross a matrix. matrix.diagonal() returns a list of values, but making changes to these does not reflect in the original (naturally). I'm just wondering if there is a way that i can