Advertisement
little_meow3

Обратная матрица

May 18th, 2022
493
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def reverse(a):
  2.     l, u = decomposition_lu(a)
  3.     n = a.shape[0]
  4.     reversed_matrix = np.matrix(np.zeros([n, n]))
  5.  
  6.     for i in range(n):
  7.         ans = np.matrix(np.zeros([n, 1]))
  8.         ans[i] = 1
  9.         x = solve_lu(l, u, ans)
  10.  
  11.         for j in range(n):
  12.             reversed_matrix[j, i] = x[j]
  13.  
  14.     return reversed_matrix
Advertisement
RAW Paste Data Copied
Advertisement