From: Johannes L. <a.u...@gm...> - 2006-10-12 06:40:59
|
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 entries of the index arrays are used as row and column indices respectively, and the result will be an array shaped like the index arrays. So doing mat[index1, index2] will give you --> array([ mat[17, 12], mat[19, 3], mat[29, 9]]). Now if you want the diagonal of a 3x3-mat, you need index1=index2=array([ 0, 1, 2]). mat[index1, index2] --> array([ mat[0,0], mat[1,1], mat[2,2]]) That is what my code does. If you need other, arbitrary subsets of mat, you just have to fill the index arrays accordingly. Johannes |