fork download
  1. import numpy as np
  2.  
  3. # 1 行目:行数
  4. n = int(input().strip())
  5.  
  6. # 2 行目以降:行列データ
  7. matrix_list = []
  8. for _ in range(n):
  9. row = list(map(int, input().split()))
  10. matrix_list.append(row)
  11.  
  12. # numpy array へ変換
  13. A = np.array(matrix_list)
  14.  
  15. # 行数と列数
  16. rows = A.shape[0]
  17. cols = A.shape[1]
  18.  
  19. print(f"rows {rows}")
  20. print(f"columns {cols}")
  21.  
  22. # 正方行列でない場合は対称行列ではない
  23. if rows != cols:
  24. print("not symmetric")
  25. else:
  26. # A と A.T(転置)が完全に一致するかチェック
  27. if np.array_equal(A, A.T):
  28. print("symmetric")
  29. else:
  30. print("not symmetric")
  31.  
Success #stdin #stdout 1.08s 41304KB
stdin
4
3 5 0 2
5 4 3 1
0 3 6 7
2 1 7 8
stdout
rows 4
columns 4
symmetric