I would like to encode a column2 () function which allows to extract all index M 2 elements , and must then generalize a

column () function to any column of a matrix of n rows by m columns . " I must use python langage and i am a bigginer in python

The objective is to extract the index or index elements 2 of each row 2 eg 3 , 6 .... .

But col2 () function will it be binary ? 2 arguments: the matrix and the index.

You must use 2 loops ... well I think!

Already for encoding an array of n rows by m columns, eg matrix (2,3) gives [ [ 1 , 2, 3 ] , [ 4 , 5, 6 ] ] .

- Code: Select all
`>>> def matrix (line, col):`

m = [ ]

for e in range ( line):

z = [ ]

for o in range ( col):

z + = [ 3 * e + o + 1]

m + = [z]

return m

_ Also, I can't use the append () method , append is supposed to add an item to the end of such a list:

I know, I didn't use the append () method to the code PX10 -1, but I found something interesting :

- Code: Select all
`>>> m = []`

m.append >>> (range (3) )

m.append >>> (range (3, 6)

m.append >>> (range (6, 9) )

>>>m

[ [0 , 1, 2 ], [3 , 4, 5 ], [6 , 7, 8 ] ] # there, it starts at 0 , but in my case here must begin with 1.

Thank you in advance!