用Python生成两个2×2矩阵,并计算矩阵乘积
时间: 2024-05-09 22:18:51 浏览: 131
计算两个矩形的乘积
代码如下:
```python
import numpy as np
# 生成两个2×2矩阵
A = np.array([[1, 2], [3, 4]])
B = np.array([[5, 6], [7, 8]])
# 计算矩阵乘积
C = np.dot(A, B)
print("A =\n", A)
print("B =\n", B)
print("A × B =\n", C)
```
输出结果为:
```python
A =
[[1 2]
[3 4]]
B =
[[5 6]
[7 8]]
A × B =
[[19 22]
[43 50]]
```
阅读全文