python 矩阵转制
时间: 2023-07-01 10:13:04 浏览: 213
在 Python 中,可以使用 numpy 库来进行矩阵转置。以下是一个示例:
```python
import numpy as np
# 定义一个 2x3 的矩阵
matrix = np.array([[1, 2, 3], [4, 5, 6]])
# 转置矩阵
transpose_matrix = np.transpose(matrix)
print("原始矩阵:")
print(matrix)
print("转置矩阵:")
print(transpose_matrix)
```
输出:
```
原始矩阵:
[[1 2 3]
[4 5 6]]
转置矩阵:
[[1 4]
[2 5]
[3 6]]
```
以上代码中,使用 numpy 库的 `transpose()` 函数将原始矩阵转置,并将结果存储在 `transpose_matrix` 中。最后,分别输出原始矩阵和转置矩阵。
阅读全文
相关推荐
![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)
![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)
![py](https://img-home.csdnimg.cn/images/20250102104920.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![docx](https://img-home.csdnimg.cn/images/20241231044901.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)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)