0
The easiest way is to declare your matrices as numpy arrays and just do matrix1 + matrix2 More on numpy here: https://www.sololearn.com/learn/6671/?ref=app But if that's not an option, here's an alternative: new_matrix =[[matrix1[i][j] + matrix2[i][j] for j in range(Y)] for i in range(X)] If nested list comprehension is not your cup of tea, try #initialize matrix new_matrix = [] for i in range(X): #initialize i-th row new_matrix.append([]) for j in range(Y): new_matrix[i].append(matrix1[i][j] + matrix2[i][j]) Hope that helps.
26th Aug 2018, 2:01 PM
Kishalaya Saha
Kishalaya Saha - avatar