Programming Examples
Write a program to perform the addition of two square matrices.
Write a program to perform the addition of two square matrices.
Solutionimport numpy as np
# Initialize two square matrices
A = np.array([[1, 2, 3],
[4, 5, 6],
[7, 8, 9]])
B = np.array([[9, 8, 7],
[6, 5, 4],
[3, 2, 1]])
# Add the matrices
C = A + B
# Display the matrices
print("First Matrix:")
print(A)
print("\nSecond Matrix:")
print(B)
print("\nSum of the Matrices:")
print(C)
Output