Feb-22-2022, 03:49 PM
hello everyone,
I struggle on this exercise:
define a function col(mat, j) allowing to retrieve a column of the matrix. For example col(M, 1) will return [2, 6, 10].
here's the matrix (list of list created with loops):
M = [[1, 2, 3, 4],
[5, 6, 7, 8],
[9, 10, 11, 12]]
so far I wrote:
can you help me understand what's wrong with my code?
I use Python 3 and Jupyter Notebook
Thanks in advance,
Leyo
I struggle on this exercise:
define a function col(mat, j) allowing to retrieve a column of the matrix. For example col(M, 1) will return [2, 6, 10].
here's the matrix (list of list created with loops):
M = [[1, 2, 3, 4],
[5, 6, 7, 8],
[9, 10, 11, 12]]
so far I wrote:
def col(mat,j): for i in range(3): #search lines for j in range(4): #search columns return M[:][j] #return all elements from i column col(0,1)
Output:[1, 2, 3, 4]
I don't understand what to do with the parameter matcan you help me understand what's wrong with my code?
I use Python 3 and Jupyter Notebook
Thanks in advance,
Leyo