Advertisement
Guest User

NICE

a guest
Nov 25th, 2017
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.60 KB | None | 0 0
  1. import numpy as np
  2.  
  3. def convert_safely(value, type):
  4.     result = None
  5.     try:
  6.         result = type(value)
  7.     except Exception:
  8.         result = None
  9.  
  10.     return result
  11.  
  12. with open('input.txt') as f:
  13.     A = [[convert_safely(x, int) for x in line.split()] for line in f]
  14.     for arr in A:
  15.         if None in arr:
  16.             raise TypeError("Не могу прочитать матрицу. Проверьте введенные данные.")
  17.  
  18. A = np.matrix(A)
  19. if A.shape[0] != A.shape[1]:
  20.     raise Exception("Требуется квадратная матрица. Проверьте введенные данные.")
  21.  
  22. N = A.shape[0]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement