-2

this is the example matrix given:

2 3 5
4 6 9
3 1 10

i have to write 2 programs, one to find the sum of all even number in the matrix and one to find the transpose of the matrix (it doesn't say you can't make one program though)

from what i understand a transposed matrix is, it means switching the rows and columns, so the above matrix would look like this

2 4 3
3 6 1
5 9 10

right now i only have code written for the transposing part because i don't even know where to start with the even number adding part:

a = [[2, 3, 5],
     [4, 6, 9],
     [3, 1, 10]]
n=len(a)
def transpose(A, B):
    for i in range(N):
        for j in range(N):
            B[i][j] = A[j][i]
print(a)
oh my god
  • 23
  • 1
  • 2
  • 7
  • are you allowed to use any libraries? Pandas has a transpose method – IoaTzimas Dec 12 '20 at 22:25
  • [sum even numbers](https://stackoverflow.com/questions/42213455/using-sum-to-print-the-sum-of-even-numbers-in-a-list) [transpose](https://stackoverflow.com/questions/4937491/matrix-transpose-in-python) – ssp Dec 12 '20 at 22:26
  • @IoaTzimas i mean it doesn't say i can't – oh my god Dec 12 '20 at 23:09

1 Answers1

1

Sum of even numbers:

sum(it for row in a for it in row if it % 2 == 0)

Transpose:

[*zip(*a)]
ssp
  • 1,666
  • 11
  • 15