Advertisement
wyx0311

电宇智控视觉组1_2

May 15th, 2024
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.59 KB | Source Code | 0 0
  1. import numpy as np
  2.  
  3. # 输入矩阵大小
  4. n = int(input(" n: "))
  5.  
  6. # 输入矩阵元素
  7. matrix = []
  8. print(f"输入n*n个整数:")
  9. for _ in range(n):
  10.     row = list(map(int, input().split()))
  11.     matrix.append(row)
  12.  
  13. # 转置矩阵
  14. transpose_matrix = np.transpose(matrix)
  15.  
  16. # 顺时针旋转90度矩阵
  17. rotate_90_matrix = np.rot90(matrix, -1)
  18.  
  19. # 输出转置矩阵
  20. print("转置后:")
  21. for row in transpose_matrix:
  22.     print(' '.join(map(str, row)))
  23.  
  24. # 输出旋转90度后的矩阵
  25. print("顺时针旋转90度后:")
  26. for row in rotate_90_matrix:
  27.     print(' '.join(map(str, row)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement