编写一函数,将一个3×3矩阵转置
时间: 2024-05-11 08:18:55 浏览: 202
矩阵_C语言_castle4zf_一个数的转置_
以下是Python语言的实现:
```python
def transpose(matrix):
"""
将一个3×3矩阵转置
"""
transposed_matrix = []
for j in range(len(matrix[0])):
temp = []
for i in range(len(matrix)):
temp.append(matrix[i][j])
transposed_matrix.append(temp)
return transposed_matrix
```
使用示例:
```python
matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
transposed_matrix = transpose(matrix)
print(transposed_matrix)
```
输出结果为:
```
[[1, 4, 7], [2, 5, 8], [3, 6, 9]]
```
阅读全文