Advertisement
Guest User

#1Z8orgj1 (Python)

a guest
Sep 16th, 2022
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.47 KB | None | 0 0
  1. import numpy as np
  2.  
  3. def get_mat(L:int)->np.ndarray:
  4.     N = L * 2 + 1
  5.     mat = np.zeros(N) - np.identity(N)
  6.     idx = np.arange(N-1)
  7.     idy = idx + 1
  8.     mat[idx[:L], idy[:L]] = 1/3
  9.     mat[idx[L:], idy[L:]] = 2/3
  10.     mat[idy[:L-1], idx[:L-1]] = 2/3
  11.     mat[idy[L-1:], idx[L-1:]] = 1/3
  12.     return mat
  13.  
  14. for i in range(11):
  15.     mat = get_mat(i)
  16.     det = np.linalg.det(mat)
  17.     mat_inv = None
  18.     if det != 0:
  19.         mat_inv = np.linalg.inv(mat)
  20.     print(mat, mat_inv)
  21.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement