Untitled

mail@pastecode.io avatar
unknown
plain_text
3 years ago
570 B
1
Indexable
Never
print('Student id: 2019-3-60-008')
import numpy as np

cw = np.array([[1,2,4],[4,5,6],[7,8,9]])
cofact = np.zeros((3,3))
k=1
inv = np.zeros((3,3))
for i in range(0,3):
  for j in range(0,3):
    d = (cw[(i+1)%3][(j+1)%3]*cw[(i+2)%3][(j+2)%3]) - (cw[(i+2)%3][(j+1)%3]*cw[(i+1)%3][(j+2)%3])
    if(k%2==0):
      d = -1*d
      k = k+1
    cofact[i][j] = d
t = np.transpose(cofact)
for i in range(0,3):
  for j in range(0,3):
    if(cofact[i][j]<0):
      cofact=cofact*-1
      inv[i][j] = t[i][j]/cofact[i][j]
    else:
      inv[i][j] = t[i][j]/cofact[i][j]

print(inv)