-
Notifications
You must be signed in to change notification settings - Fork 0
/
AnyMatrix.py
72 lines (58 loc) · 1.4 KB
/
AnyMatrix.py
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
66
67
68
69
70
71
72
import numpy as np
import sys
from fractions import Fraction as fn
# 设置矩阵输出用分数形式
np.set_printoptions(formatter={'all':lambda x:str(fn(x).limit_denominator())})
global a,b
a=np.array([
[9,2,3],
[2,3,4],
[0,1,1]
])
b=np.array([[9,2,3],
[2,3,4],
[0,1,1]])
global row_a,row_b,col_a,clo_b
def multi_(a,b):
global mul_a_b
mul_a_b=np.dot(a,b)
def transposition(a):
global tsp_a_b
tsp_a_b=a.T
def det(a):
global det
det=np.linalg.det(a)
def inverse(a):
global inv_M
inv_M =np.linalg.inv(a)
def adjoint(a):
global ad
det(a)
inverse(a)
ad =det*inv_M
def main():
if sys.argv[1]=="multi":
multi_(a,b)
print(mul_a_b)
elif sys.argv[1]=="transposition":
transposition(a)
print(tsp_a_b)
elif sys.argv[1]=="det":
det(a)
print(det)
elif sys.argv[1]=="inv":
if det(a)==0:
print("det(a)==0")
else:
inverse(a)
print(inv_M)
elif sys.argv[1]=="adjoint":
adjoint(a)
print(ad)
if __name__=="__main__":
try:
main()
except :
print('\033[37;41m',"Please check matrixes you have input again,repython it.",end="")
print('\033[0m',end="")
sys.exit(0)