[Tutor] matrix q?

Evripides Loizides loizie@hotmail.com
Sat Jun 7 00:37:01 2003


<html><div style='background-color:'><DIV>
<P>i want to add the row of a square matrix. </P>
<P>the code i have is :</P>
<P>myMatrix = [2,7,6], [9,5,1], [4,3,8]</P>
<P>def sumRow(aMatrix, index):<BR>&nbsp;&nbsp;&nbsp; sum = 0<BR>&nbsp;&nbsp;&nbsp; for item in aMatrix[index]:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sum = sum + item<BR>&nbsp;&nbsp;&nbsp; print aMatrix[index]<BR>&nbsp;&nbsp;&nbsp; return sum<BR>&nbsp;&nbsp;&nbsp; <BR>#print sumRow(myMatrix,len(myMatrix)-1)<BR>print sumRow(myMatrix,0)&nbsp;&nbsp;&nbsp; <BR>#print sumRow(myMatrix,1)</P>
<P>&nbsp;</P>
<P>Changing from 0 to 1 and len(myMatrix)-1 i can get the sum of the row each time but i want to put the in a loop so i can&nbsp;get the sum&nbsp;of&nbsp;all row indevidual&nbsp;&nbsp;the&nbsp; same time. </P>
<P>I am looking forward for some good ideas</P>
<P>thanks<BR><BR></P></DIV></div><br clear=all><hr>Protect your PC - <a href="http://g.msn.com/8HMJENUS/2755??PS=">Click here</a> for McAfee.com VirusScan Online </html>