编写程序输入一个3×4的矩阵 求出它的转置矩阵并输出
时间: 2023-09-10 18:15:43 浏览: 104
Java程序求矩阵转置.docx
好的,下面是 Python 代码实现:
```python
# 定义原矩阵
matrix = [
[1, 2, 3, 4],
[5, 6, 7, 8],
[9, 10, 11, 12]
]
# 定义转置矩阵
transpose = [
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0]
]
# 计算转置矩阵
for i in range(len(matrix)):
for j in range(len(matrix[0])):
transpose[j][i] = matrix[i][j]
# 输出转置矩阵
for row in transpose:
print(row)
```
输出结果为:
```
[1, 5, 9]
[2, 6, 10]
[3, 7, 11]
[4, 8, 12]
```
阅读全文