请输入两个矩阵,用循环结构写矩阵点乘。例如有两个矩阵A和B,它们的维度分别为(m,n)和(n,p),矩阵点乘的结果C的维度为(m,p)
时间: 2023-05-27 09:03:21 浏览: 35
用C语言实现矩阵运算.doc
#输入两个矩阵
m1 = [[1, 2],
[3, 4],
[5, 6]]
m2 = [[1, 2, 3],
[4, 5, 6]]
#维度计算
m = len(m1)
n = len(m1[0])
p = len(m2[1])
#初始化结果矩阵
result = [[0]*p for i in range(m)]
#循环计算结果矩阵
for i in range(m):
for j in range(p):
for k in range(n):
result[i][j] += m1[i][k]*m2[k][j]
#输出结果矩阵
for row in result:
print(row)
阅读全文