Python Program to find Matrix Addition

Last Updated:

Find Matrix Addition

In the following example, we will add the two given matrices (two-dimensional arrays).

Example

Python Compiler
arr1 = [ [1, 1, 1], [1, 1, 1], [1, 1, 1] ] arr2 = [ [2, 2, 2], [2, 2, 2], [2, 2, 2] ] arr3 = [[0]*3 for _ in range(3)] print("Matrix A (3 x 3):") for i in range(0, 3): for j in range(0, 3): print(arr1[i][j], end=" ") print() print("\nMatrix B (3 x 3):") for i in range(0, 3): for j in range(0, 3): print(arr2[i][j], end=" ") print() for i in range(0, 3): for j in range(0, 3): arr3[i][j] = arr1[i][j] + arr2[i][j]; print("\nMatrix Additon (A + B):") for i in range(0, 3): for j in range(0, 3): print(arr3[i][j], end=" ") print()

Share this Page

Meet the Author