Jul-20-2019, 07:04 PM
(This post was last modified: Jul-20-2019, 07:14 PM by ricardodepaula.)
Hi! I'm new to programming and I'm racking my brain to try to find an sum the diagonal of a matrix using map and lambda.
the matrix:
[inline]
matrix = [
[3],
[11,2,4],
[4,5,6],
[10,8,-12]
]
[/inline]
my code so far:
my idea was to use the same logic of sum function.
but it does not work.
the matrix:
[inline]
matrix = [
[3],
[11,2,4],
[4,5,6],
[10,8,-12]
]
[/inline]
my code so far:
diagonal_r = list(map(lambda i: sum(i[0],i[1][1]), matrix ))
my idea was to use the same logic of sum function.
diagonal_r = sum(matrix[0],matrix[1][1],matrix[2][2],matrix[3][2])
but it does not work.