numpy
import numpy as np
def inputMat():
R = int(input("Enter the number of rows:"))
C = int(input("Enter the number of columns:"))
print("Enter the entries in a single line ")
elements = list(map(int, input().split()))
matrix = np.array(elements).reshape(R, C)
print("Inserted matrix: \n", matrix)
return matrix
def input2Mat(R, C):
print("Enter the entries : ")
elements = list(map(int, input().split()))
matrix = np.array(elements).reshape(R, C)
print("Inserted matrix: \n", matrix)
return matrix
def DiffofSum(mat, r, c):
i, j = 0, 0
upper_sum = 0
lower_sum = 0
# Sum of upper triangle
for i in range(r):
for j in range(c):
if i <= j:
upper_sum += mat[i][j]
# Sum of lower
for i in range(r):
for j in range(c):
if j <= i:
lower_sum += mat[i][j]
return upper_sum - lower_sum
while True:
print("\nMenu:")
print("1. Matrix Addition")
print("2. Matrix Subtraction")
print("3. Scalar Matrix Multiplication")
print("4. Elementwise Matrix Multiplication")
print("5. Matrix Multiplication")
print("6. Matrix Transpose")
print("7. Trace of a Matrix")
print("8. Solve System of Linear Equations")
print("9. Determinant")
print("10. Inverse")
print("11. Singular Value Decomposition")
print("12. Eigen Value")
print("13. Search an Element")
print("14. Sum of Difference of Upper and Lower Triangular Matrix")
print("15. Exit")
choice = int(input("Please choose an option: "))
if choice == 1:
print("Matrix 1:")
matrix1 = inputMat()
print("Matrix 2:")
matrix2 = inputMat()
print("Output matrix:\n", np.add(matrix1, matrix2))
elif choice == 2:
print("Matrix 1:")
matrix1 = inputMat()
print("Matrix 2:")
matrix2 = inputMat()
print("Output matrix:\n", np.subtract(matrix1, matrix2))