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
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
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
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]])
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
> 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
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