这是python 矩阵乘法的简单例子
col = 2
row = 2
a = [[1, 2],
[3, 4]]
b = [[5, 6],
[7, 8]]
c = [[0, 0],
[0, 0]]
“”"
a b c 二维矩阵初始化
c = [[0 for col in range(col)] for row in range(row)]
a = [[0 for col in range(col)] for row in range(row)]
b = [[0 for col in range(col)] for row in range(row)]
for i in range(0, row):
for j in range(0, col):
for k in range(0,5):
c[i][j] += a[i][k] * b[k][j]
“”"
C = [[a[i][k] * b[k][j] + c[i][j]] for i in range(0, row) for j in range(0, col) for k in range(0, 2)]
B = [C[i][0] + C[i + 1][0] for i in range(0, len©, 2)]
print(B)
AAA = [B[i:i+2:1] for i in range(0, 4, 2)]
print(AAA)