python矩阵转置pta山东理工大学
时间: 2023-10-28 16:55:29 浏览: 207
题目描述:
给定一个N×M的矩阵A,要求将其转置后输出。
输入格式:
第一行包含两个整数N和M。
接下来N行,每行包含M个整数,表示矩阵A中的元素。
输出格式:
输出M行,每行包含N个整数,表示矩阵A的转置矩阵。
输入样例:
3 4
1 2 3 4
5 6 7 8
9 10 11 12
输出样例:
1 5 9
2 6 10
3 7 11
4 8 12
解题思路:
矩阵转置即将矩阵的行列互换。可以直接使用Python中的zip函数实现,zip函数可以将多个列表或元组中的对应元素打包成元组,然后返回这些元组组成的列表。
代码如下:
阅读全文
相关推荐
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![py](https://img-home.csdnimg.cn/images/20250102104920.png)
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)