pastebin

Paste Search Dynamic
Recent pastes
get diag mat
  1. import numpy as np
  2.  
  3. mat = np.array([
  4.         [1, 2, 3],
  5.         [4, 5, 6],
  6.         [7, 8, 9],
  7. ])
  8.  
  9. def get_diag_mat(mat):
  10.         rows, cols = mat.shape
  11.         assert rows == cols, "Matrix isn't square"
  12.  
  13.         new_mat = np.zeros(mat.shape)
  14.  
  15.         for i in range(rows):
  16.                 new_mat[i][rows-i-1] = mat[i][rows-i-1]
  17.  
  18.         return new_mat
  19.  
  20.  
  21. print(get_diag_mat(mat))
Parsed in 0.005 seconds