From: Bill B. <wb...@gm...> - 2006-10-11 23:58:47
|
On 10/12/06, David Novakovic <da...@di...> 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]]) > >>> index = arange(min(x.shape[0],x.shape[1])) > >>> x[index,index] += 1 > >>> x > array([[1, 0, 0], > [0, 1, 0], > [0, 0, 1], > [0, 0, 0], > [0, 0, 0]]) Exactly what output are you expecting? That is the definition of the 'diagonal' for a non-square matrix. If you're expecting something else then what you want is not the diagonal. > Just for reference, this is the line of perl i'm trying to port: > > > like: > > for index in diag_iter(matrix,*axes): > matrix[index] +=1 That's not going to change the mathematical definition of the diagonal of a non-square matrix. > PS: If anyone would care to link me to the subscription page for the > mailing list so you dont have to CC me all the time :) Check the bottom of this message. > _______________________________________________ > Numpy-discussion mailing list > Num...@li... > https://lists.sourceforge.net/lists/listinfo/numpy-discussion > --bb |