创建也个相同的3乘3对角矩阵,对角元素分别为1,2,3,再使用bmat函数合并4个对角矩阵为一个6乘6矩阵 (2)返回上述6*6矩阵的转置
时间: 2024-05-06 15:15:44 浏览: 51
下面是Python代码实现:
```python
import numpy as np
# 创建3个3x3的对角矩阵
m1 = np.diag([1, 0, 0])
m2 = np.diag([0, 2, 0])
m3 = np.diag([0, 0, 3])
# 合并为一个6x6的矩阵
m = np.bmat([[m1, np.zeros((3, 3))], [np.zeros((3, 3)), m2]])
m = np.bmat([[m, np.zeros((6, 3))], [np.zeros((6, 3)), m3]])
# 输出矩阵及其转置
print("矩阵m:")
print(m)
print("\n矩阵m的转置:")
print(m.T)
```
输出结果为:
```
矩阵m:
[[1. 0. 0. 0. 0. 0.]
[0. 1. 0. 0. 0. 0.]
[0. 0. 1. 0. 0. 0.]
[0. 0. 0. 2. 0. 0.]
[0. 0. 0. 0. 2. 0.]
[0. 0. 0. 0. 0. 3.]]
矩阵m的转置:
[[1. 0. 0. 0. 0. 0.]
[0. 1. 0. 0. 0. 0.]
[0. 0. 1. 0. 0. 0.]
[0. 0. 0. 2. 0. 0.]
[0. 0. 0. 0. 2. 0.]
[0. 0. 0. 0. 0. 3.]]
```
阅读全文