[Tutor] matrix q?

Alan Gauld alan.gauld@blueyonder.co.uk
Sat Jun 7 17:52:01 2003


> the think i notice is for the down diagonal the numbers 
> locate like this 00 11 22 for a 3 by 3 matrix.
> 
> whats the easy way to get that :

for n in range(len(aMatrix)):
    item = aMatrix[n][n]


> def sumOfDownDiag(aMatrix,index):
>     sum = 0
>     xIndex = 0
>     yIndex = 0
>     for item in aMatrix[[xindex],[yindex]]:

This makes no sense whatever.

[xindex] is a list of one element, as is [yindex]

so you are passing two lists as indices

aMatrix[list1,list2]

Python doesn't know what to do with that.
To reference a two dimensional table you need two separate 
indices:

aMatrix[n]  # -> returns the nth row of the table

aMatrix[n][m]  #-> returns the mth element of the nth row

HTH,

Alan G