-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatrix_operations.py
More file actions
65 lines (50 loc) · 1.44 KB
/
Copy pathmatrix_operations.py
File metadata and controls
65 lines (50 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import numpy as np
while True:
print("\n===== Matrix Operations Tool =====")
print("1. Addition")
print("2. Subtraction")
print("3. Multiplication")
print("4. Transpose")
print("5. Determinant")
print("6. Exit")
choice = int(input("Enter your choice (1-6): "))
if choice == 6:
print("Thank you for using Matrix Operations Tool!")
break
# Matrix Input
print("\nEnter Matrix A")
a11 = int(input("Enter A11: "))
a12 = int(input("Enter A12: "))
a21 = int(input("Enter A21: "))
a22 = int(input("Enter A22: "))
A = np.array([[a11, a12],
[a21, a22]])
print("\nEnter Matrix B")
b11 = int(input("Enter B11: "))
b12 = int(input("Enter B12: "))
b21 = int(input("Enter B21: "))
b22 = int(input("Enter B22: "))
B = np.array([[b11, b12],
[b21, b22]])
print("\nMatrix A:")
print(A)
print("\nMatrix B:")
print(B)
# Perform operation
if choice == 1:
print("\nResult (Addition):")
print(A + B)
elif choice == 2:
print("\nResult (Subtraction):")
print(A - B)
elif choice == 3:
print("\nResult (Multiplication):")
print(np.dot(A, B))
elif choice == 4:
print("\nTranspose of Matrix A:")
print(A.T)
elif choice == 5:
print("\nDeterminant of Matrix A:")
print(np.linalg.det(A))
else:
print("\nInvalid Choice!")