[Tutor] matrix q? print the first column of matrix

Lloyd Kvam pythontutor@venix.com
Sat Jun 7 23:03:02 2003


An alternative is to transpose the matrix.

myTranspose = zip(*myMatrix)
myTranspose[0] would be the first column of myMatrix.

This isn't better unless you really want the transpose
The * before a list argument to a function causes the list to be
processed as separate arguments to the function.  So your 3x3
matrix is processed as 3 lists by zip.  (I hope that was clear.)

Bob Gailer wrote:
> At 12:09 PM 6/7/2003 -0500, evros loizides wrote:
> 
>> i am try to print the columns of a square matrix but i getting only 
>> the first number
>> for example  myMatrix = [[2,3,4],[4,5,6],[7,8,9]]
>> i want to print the first column only .
>> how can i do that?
> 
> 
> print [row[0] for row in myMatrix]
> 
> Bob Gailer
> bgailer@alum.rpi.edu
> 303 442 2625
> 


-- 
Lloyd Kvam
Venix Corp.
1 Court Street, Suite 378
Lebanon, NH 03766-1358

voice:	603-443-6155
fax:	801-459-9582